The purpose of this article is revealing the unrevealed parts of the bitwise XOR.
As we aware, the truth table for the XOR operator is :
A B A^B
0 0 0
0 1 1
1 0 1
1 1 0
For example , 1^2 will be calculated as given below:
First the operands are being converted to their respective binary forms and the xor operation is being performed.
1== 001
2== 010
1^2==011==3
pandeeswaran@ubuntu:~$ echo $(( 1 ^ 2 ))
3
The interesting finding over here is:
pandeeswaran@ubuntu:~$ echo $(( 2 ^ 3 ))
1
pandeeswaran@ubuntu:~$ echo $(( 4 ^ 5 ))
1
pandeeswaran@ubuntu:~$ echo $(( 124 ^ 125 ))
1
pandeeswaran@ubuntu:~$ echo $(( 12452 ^ 12453 ))
1
pandeeswaran@ubuntu:~$ echo $(( 124524567878 ^ 124524567879 ))
1
pandeeswaran@ubuntu:~$ echo $(( 121111111111111111111111111111111111111111110 ^ 121111111111111111111111111111111111111111111 ))
1
In general, if the operands are in the form of n ^ (n+1) and also n is an even number, then the result is always 1.
XOR operation between strings:
pandeeswaran@ubuntu:~$ echo $(( password1 ^ _ ))
0
pandeeswaran@ubuntu:~$ echo $(( A ^ A ))
0
pandeeswaran@ubuntu:~$ echo $(( A ^ B ))
0
pandeeswaran@ubuntu:~$ echo $(( A ^ BS ))
0
pandeeswaran@ubuntu:~$ echo $(( AA ^ BS ))
0
pandeeswaran@ubuntu:~$ echo $(( AAA ^ BAS ))
0
pandeeswaran@ubuntu:~$ echo $(( A1 ^ BAS ))
0
pandeeswaran@ubuntu:~$ echo $(( A1 ^ B1 ))
0
It�s tacit that the xor operation between the strings of arbitrary length is undefined.
But the same in perl is behaving differently:
pandeeswaran@ubuntu:~$ perl -e �print A ^ C;printf �\n��
pandeeswaran@ubuntu:~$ perl -e �print A ^ B;printf �\n��
A=65= 01000001
B=66= 01000010
���������-
00000011=3
A=65=01000001
C=67=01000011
���������
00000010=2
we can easily relate the above with the result we are getting in perl.
But when we encode this result with base64 method, we will get some meaningful text.
In this way it can be used as an encryption technique.
pandeeswaran@ubuntu:~$ perl -e �print A ^ B;printf �\n��|base64
Awo=
pandeeswaran@ubuntu:~$ perl -e �print Password1 ^ _________;printf �\n��|base64
Dz4sLCgwLTtuCg==