I was searching the Internet for a string based XOR function and I was unable to come up with anything. There were people looking but a lot of "experts" claimed that there was no such thing. I decided to take it upon myself to see if they were correct or not.
Remove these ads by
Signing UpStep 1What the heck is XOR
First for a little background. XOR (exclusive OR) is what's called a bit-wise operation. It breaks down into a truth table as follows:
A(in) B(in) C(out)
0 0 0
1 0 1
0 1 1
1 1 0
This may seem a little less than impressive but it has larger applications especially in the field of encryption. If you put two bytes together via bit-wise XOR the result and one of the original inputs will return the second input.
Example:
If A=010101
and B=101010 then an XOR operation would result
C=111111.
If C=111111
and B=101010 then an XOR operation would result
010101 which is A
the same is true of the XOR of C and A = B.
So there you have an overview of bit-wise XOR operation and the application that I am interested in.
.
| « Previous Step | Download PDFView All Steps | Next Step » |













































Because bitwise logic has been around for that for ages.
A xor B could be written as
R = (~A & B) ¦ (A & ~B) where A and B are any given integers. You'd simply have to go through the string a character (or byte) at a time, running this function on it.