Intro
---------------
XOR stands for "exclusive or". It's a form of OR where if you have two boolean inputs, your output will be true only if one or the other inputs are true.. but NOT both. Hence the exclusive bit.
A B Out
0 0 0
0 1 1
1 0 1
1 1 0
Now if you think of A as the input and B as something you can manipulate, you might notice that the input A is inverted (ie 1->0 and 0->1) when B is set to 1. and that the input A is left alone when B is set to 0.
It's in this way that XOR can be used to invert bits in a file.
Characters
---------------
What about XOR'ing characters? like 'a' ^ 'b' or something like that. (^ is an operator in C [and possibly PHP] that XORs two characters or numbers together)
Well to the computer, 'a' and 'b' are binary sequences 1100001 and 1100010 respectively. So when you XOR them together, it'll look at each bit respectively.
so
1100001 'a' XOR
1100010 'b'
--------
0000011
You can follow the table at the top and see that only the last two binary digits will produce a 1.
"Encryption"
---------------
So what about encryption? For simple encryption, you want to be able to encrypt and decrypt to get the data back.
So if I have 'a' and XOR with 'b' you get 0000011 (as shown above) but if we XOR the answer with 'b' again:
0000011 XOR
1100010 'b'
--------
1100001 = 'a' !!!
So if you have 'a' ^ 'b' ^ 'b' you get 'a' again! This is the basis of XOR encryption in AGI object files.
The only difference is that you use a string "Avis Durgan", so you go through each character in the string you want to encrypt and XOR with 'A' for the 1st, 'v' for the 2nd and so on..
I hope this made sense!
- Nick