 # Secret Key Cryptography

• Print
This chapter is from the book

## Basic XOR

The XOR operation denoted by + is a bit-wise function that maps an element of {0, 1}x{0,1} onto the set {0, 1} as follows:

```0 +0 =0
0 +1 =1
1 +0 =1
1 +1 =0```

If we take the second operand to be a key value, the XOR operation can be thought of as being simply a bit-level substitution based upon the bit values of the key. With such assumption, XOR sends a 0 or 1 to itself when the corresponding key bit is 0 and inverts a 0 into a 1 and a 1 into a 0 when the corresponding key bit is 1. XOR exhibits the following properties.

```a +0 =a
a +a =0,and thus
a +b +b =a```

The last property implies that using a fixed key value, the XOR operation can be applied to encipher a plaintext, which can then be recovered by simply applying the XOR operation to the ciphertext and the same key value. This property has led to the proliferation of many variants of weak encryption methods that solely rely on the simple XOR operation and thus are easily breakable.

Assume that a fixed-length key, K, is used for the XOR of some plaintext blocks. Knowing a block of plaintext, P, and its XOR transformation directly leads to K, by way of XORing the plaintext with the corresponding ciphertext.

```C =P +K
P +C =P +P +K
=K```

Similarly, by knowing two ciphertext blocks alone one can XOR them together to yield the XOR of the corresponding plaintext blocks as follows:

```C1 +C2 =P1 +K +P2 +K
=P1 +P2```

Examining the bit patterns of P1 + P2 can easily result in recovering one of the plaintexts. The latter can then be XORed with its ciphertext to yield the keystream.

By transforming one bit at a time the XOR operation lends itself well to a class of encryption algorithms known as stream ciphers. In contrast, block ciphers divide a plaintext into identical size blocks, generally of length greater or equal to 64 bits, then apply the same encryption transformation to encrypt each block at a time. Stream ciphers are geared for use in situations where memory buffering is limited or when characters are individually transformed as they show up at an endpoint of a transmission medium. Because they generally transform plaintext bits independently from one another, error propagation remains limited in the event of transmission anomaly. FIGURE 1.4 A simple one-time pad based on the XOR operation