Recently I studied about encryption; It was quite hard for me to catch up but at least now I know a little bit about it. My target was simple, I am able to implement most simple encryption by my self. After reading some article and tutorial I found about XOR chipper.

What is it?

XOR operation is simple; If there is two clause and one of them is true so the result is true, but not if both of them true.

So here is truth table of XOR operation :

A | B | XOR
-------------
F | F | False
T | F | True
F | T | True
T | T | False

The special part of XOR operation result is you can’t tell which input is true or false by looking from the result. Also when you apply it for second time with same key, it means you decrypt it.

What I like about XOR chipper (by what I read) is quite hard to crack when used properly. You can find what it properly means here.

There are a lot of samples of XOR chipper implementation in any programming language, but here is my version.

string xor_crypt(string data, string key)
{
string encrypted = data;
int keyPos=0;
for(int a=0;a<data.size();a++)
{
if(keyPos==key.size())
keyPos = 0;
encrypted[a] = data[a] ^ key[keyPos];
keyPos++;
}
return encrypted;
}

Tips :

- Use long and strong key
- Apply more than one time if possible

### Like this:

Like Loading...

*Related*