1 XOR 1 is 0
1 XOR 0 is 1
0 XOR 1 is 1
0 XOR 0 is 0
Let us write a simple C program to XOR a string cat with the key KEY:
#include <stdio.h>
int main()
{
char string[4]="cat";
char key[4]="KEY";
for(int x=0; x<3; x++)
{
string[x]=string[x]^key[x];
printf("%c",string[x]);
}
printf("\n");
return 1;
}
Note that ^ represents an XOR operation in the C programming language.
Now let’s compile it:
$ gcc xor.c -o xor
And run it to see the output:
$ ./xor
($-
The XOR operation of cat and KEY results in the output ($-. This is because the program
performs an XOR operation of c with K, a with E, and t with Y. Let’s analyze one of these oper-
ations, c with K. The ASCII value of c is 99 , which is represented in binary as 01100011. The
ASCII value of K is 75, which is represented in binary as 01001011. Now let us XOR these two
values:
01100011
(XOR) 01001011
--------
130 CHAPTER 5: THE IDIOT BOX—ATTACKING “SMART” TELEVISIONS