An example of a symmetric key cryptosystem is one that uses the XOR (= exclusive 'or': ⊕) bit-wise operation. Before showing examples of using the XOR operation for both encryption and decryption, let's recall how XOR works.
XOR accepts two bits, Bit 1 and Bit 2 (each of which is either 0 or 1,) and produces a single bit as a result. The following truth table tells the result of XOR for all the configurations of Bit 1 and Bit 2:
Bit 1 | Bit 2 | ⊕ |
---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
In other words, if Bit 1 ≠ Bit 2 (0 and 1, or 1 and 0), the result will be 1. Otherwise, if Bit 1 = Bit 2, the result will be a 0.