Jump to content

A little Xor encoding for more security ^^


Qousio
 Share

Recommended Posts

Hello!

I have noticed theres quite a few people asking how to safely encode/protect passwords or text.

My method is far from good, the main purpose is for extra encoding to already encoded text. Although you can use this for just encoding.

Heres an example, I made it simple to understand so anybody can alter/expand it.

$Message = String("Trying to Xor this text")
$Key = 88
$Length = StringLen($Message)
$Array = StringToASCIIArray($Message)

MsgBox(0, "", "The original ASCII is: " & $Array[0])
For $i = 0 To $Length - 1 Step 1
    $Array[$i] = BitXOR($Array[$i], $Key)
Next
MsgBox(0, "", "The encoded ASCII is: " & $Array[0])

$Chr = Chr($Array[0])

MsgBox(0, "", "The encoded char is: " & $Chr)

$Array[0] = BitXOR($Array[0], $Key)

$Chr = Chr($Array[0])

MsgBox(0, "", "The decoded char is: " & $Chr)

For example, you encoded some text with hashing, randomizing, stringexploding, whatever.

Insert the code you got here, and its encoded just a bit more :)

You can run this script multiple times with different keys, aka:

For $Key to 0 Step -1

And then reverse it the same way, which will result in a decently encoded text.

Here is a working example:

#include <Array.au3>

$Message = String("Insert your text or encoded text here")
$Key = 88
$Length = StringLen($Message)
$Array = StringToASCIIArray($Message)
Dim $Chr[StringLen($Message)]

_ArrayDisplay($Array);This is the original ASCII
For $i = 0 To $Length - 1 Step 1
    $Array[$i] = BitXOR($Array[$i], $Key)
Next
_ArrayDisplay($Array);This is the encoded ASCII

For $i = 0 To $Length - 1 Step 1
    $Chr[$i] = Chr($Array[$i])
Next

_ArrayDisplay($Chr);This is the encoded text

For $i = 0 To $Length - 1 Step 1
    $Chr[$i] = BitXOR($Array[$i], $Key)
Next

_ArrayDisplay($Chr);This is the decoded ASCII

For $i = 0 To $Length - 1 Step 1
    $Chr[$i] = Chr($Chr[$i])
Next

_ArrayDisplay($Chr);This is the decoded text
Edited by Qousio
Link to comment
Share on other sites

Very Nice... Thanks for sharing :)

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

I just have one question now...

how come if I add 4 at the Xor's Result (so BitXOR($Array[$i], $Key)+4) during Encryption and Subtract 4 during decryption the string gets messed up ?

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

I just have one question now...

how come if I add 4 at the Xor's Result (so BitXOR($Array[$i], $Key)+4) during Encryption and Subtract 4 during decryption the string gets messed up ?

Because you must only change the key, adding 4 to it would just change the bits. For example:

Xor

0 1 1 1 1 1 1 1

1 0 1 1 1 0 0 1

Would be: 1 1 0 0 0 1 1 0

Adding 4 to it would be 11001010

However, Xor

0 1 1 1 1 1 1 1

(1 0 1 1 1 0 0 1) + 4 = 10111101

Would be 1 1 0 0 0 1 1 0

Hope that answered your question :)

Link to comment
Share on other sites

_StringEncrypt() is also a simple build-in function (look in the help file).

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

_StringEncrypt() is also a simple build-in function (look in the help file).

UEZ

I know :)

As I mentioned above: "My method is far from good, the main purpose is for extra encoding to already encoded text. Although you can use this for just encoding."

So basically you Hash it or StringEncrypt and then run this, double encoding, double the fun =P

Link to comment
Share on other sites

Because you must only change the key, adding 4 to it would just change the bits. For example:

Xor

0 1 1 1 1 1 1 1

1 0 1 1 1 0 0 1

Would be: 1 1 0 0 0 1 1 0

Adding 4 to it would be 11001010

However, Xor

0 1 1 1 1 1 1 1

(1 0 1 1 1 0 0 1) + 4 = 10111101

Would be 1 1 0 0 0 1 1 0

Hope that answered your question :)

yes thanks :party:

a similar thing was done on a bitmap to encode messages in it I believe

great work anyway :idea:

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...