previous | start | next

Implementing a Simple Substitution Cypher

Whilst it's not considered even slightly useful for a "production quality" encryption system when used alone, 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 production "single-key" systems, unlike "Public Key" systems, see next lecture. The XOR function is a key component in these "Real World" algorithms.
 
Lecture 16: Introduction to Encryption Copyright © 2003 P.Scott, La Trobe University Bendigo.



previous | start | next