previous | start | next

Implementing a Simple Substitution Cipher

Whilst it's not considered even slightly useful for a "production quality" encryption system, the Exclusive-OR (or XOR function is worth examining as a simple example of a symmetric encryption method. XOR is a bitwise (or Boolean) operator, with the following truth table:
  A     B     A XOR B  
0 0 0
0 1 1
1 0 1
1 1 0
Most programming languages provide an XOR function. To "encrypt" (for example) a byte of data, we could do (in Java, all variables of Java primitive type "byte"):
cipher = plainText ^ key;
The symmetric aspect of XOR comes from the fact that to recover the plain text, we can simply repeat the operation on the ciphertext:
plainText = cipher ^ key;
Symmetic encryption and decyption (ie, using the same algorithm and key to both encrypt and decrypt) is a characteristic of all "single-key" encryption systems, unlike "Public Key" systems, see next lecture. The XOR function is used one component among many in "Real World" encryption algorithms.
 


previous | start | next