Heading
Hello 0x00’ers. I thought it would be cool to make a post specific to XOR encryption.
At the moment my main focus is getting the basics of python down but, that doesn’t mean I don’t have the time for a little fun with c++ I’m not the most knowledgeable person so I apologize if I make a mistake or leave something out.
So xor(Exclusive Or) is a logic gate that says “The output can only be True if one input is True and one input False.”
Examples
1 0 = 1
True True = false
0 0 = 0
False True = True
Now the cool thing is, this can be used for encryption. You simply input a string and xor it by a single char(using a for loop) or by a string of the same size as the one being encrypted.
Example
[‘A’, ‘R’, ‘P’, ‘A’, ‘n’, ‘e’, ‘t’, ‘\0’]
we have a string of ASCII characters(‘ARPAnet’) that we then convert to binary
01000001 01010010 01010000 01000001 01101110 01100101 01110100
now lets xor that string by another 7 character string such as racecar
using the logic we talked about above
[‘r’, ‘a’, ‘c’, ‘e’, ‘c’, ‘a’, ‘r’, ‘\0’]
01110010 01100001 01100011 01100101 01100011 01100001 01110010
ARPAnet
01000001 01010010 01010000 01000001 01101110 01100101 01110100
racecar xor
01110010 01100001 01100011 01100101 01100011 01100001 01110010
and we get
00110011 00110011 00110011 00100100 00001101 00000100 00000110
which can then be translated back into it’s ASCII text form to get “333$”.
Notice how there are not 7 characters like there were in ARPAnet and racecar. This is because some bytes do not “translate” into ASCII characters after they got xor’d. This makes decryption hard if you just have the encrypted string instead of the actual encrypted bytes.
To decrypt you would xor the flipped bits using the same key.
encrypted binary
00110011 00110011 00110011 00100100 00001101 00000100 00000110
racecar xor
01110010 01100001 01100011 01100101 01100011 01100001 01110010
and you would get your old message back
01000001 01010010 01010000 01000001 01101110 01100101 01110100
I made a little script to automate this. Unfortunately it doesn’t like spaces so you will need to use another character such as a dash or underscore.
the script will be linked here
Have fun and stay frosty