Home > Articles > Security > Software Security

  • Print
  • + Share This
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.

The one-time XOR pad

Despite the simplicity of the XOR operation and the weakness of encryption algorithms that use it with fixed keys, there is a way of making the sole use of such basic operations result in a perfect encryption scheme. If the keystream digits are randomly generated and each keystream is used only once, the resulting ciphertext referred to as a one-time pad yields a perfect cipher. Such a cipher is provably secure against attacks in which a code breaker has knowledge of a set of ciphertexts. Figure 1.4 is a graphic illustration of the simple XOR-based one-time pad cipher.

Figure 1.4FIGURE 1.4 A simple one-time pad based on the XOR operation

The security of the one-time pad is due to the uncertainty in attempting to guess the keystream is equal to that of directly guessing the plaintext. Note that the length of the keystream for the one-time pad is equal to that of the plaintext being encrypted. Such a property makes it difficult to maintain and distribute very long keystreams which has led to the development of stream ciphers whereby the keystream is pseudorandomly generated from a fixed secret key that is manageable.

The bit-level one-time pad applies equally well at the character level. In fact, historically a one-time pad was applied to characters when it was first invented by Major Joseph Mauborgne and Gilbert Vernam. Each keypad character is applied to only one plaintext character. The receiving entity uses the same keypad to decrypt the cipher and then destroys the key.

  • + Share This
  • 🔖 Save To Your Account