2.2 Affine Ciphers

The shift ciphers may be generalized and slightly strengthened as follows. Choose two integers α and β, with gcd(α, 26)=1, and consider the function (called an affine function)

xαx+β (mod26).

For example, let α=9 and β=2, so we are working with 9x+2. Take a plaintext letter such as h(=7). It is encrypted to 97+26513 (mod26), which is the letter N. Using the same function, we obtain

affine CVVWPM.

How do we decrypt? If we were working with rational numbers rather than mod 26, we would start with y=9x+2 and solve: x=19(y2). But 19 needs to be reinterpreted when we work mod 26. Since gcd(9, 26)=1, there is a multiplicative inverse for 9 (mod26) (if this last sentence doesn’t make sense to you, read Section 3.3 now). In fact, 931 (mod26), so 3 is the desired inverse and can be used in place of 19. We therefore have

x3(y2)3y63y+20 (mod26).

Let’s try this. The letter V(=21) is mapped to 321+20835 (mod26), which is the letter f. Similarly, we see that the ciphertext CVVWPM is decrypted back to affine. For more examples, see Examples 2 and 3 in the Computer Appendices.

Suppose we try to use the function 13x+4 as our encryption function. We obtain

 input ERRER.

If we alter the input, we obtain

 alter ERRER.

Clearly this function leads to errors. It is impossible to decrypt, since several plaintexts yield the same ciphertext. In particular, we note that encryption must be one-to-one, and this fails in the present case.

What goes wrong in this example? If we solve y=13x+4, we obtain x=113(y4). But 113 does not exist mod 26 since gcd(13, 26)=131. More generally, it can be shown that αx+β is a one-to-one function mod 26 if and only if gcd(α, 26)=1. In this case, decryption uses xαyαβ (mod26), where αα1 (mod26). So decryption is also accomplished by an affine function.

The key for this encryption method is the pair (α, β). There are 12 possible choices for α with gcd(α, 26)=1 and there are 26 choices for β (since we are working mod 26, we only need to consider α and β between 0 and 25). Therefore, there are 1226=312 choices for the key.

Let’s look at the possible attacks.

  1. Ciphertext only: An exhaustive search through all 312 keys would take longer than the corresponding search in the case of the shift cipher; however, it would be very easy to do on a computer. When all possibilities for the key are tried, a fairly short ciphertext, say around 20 characters, will probably correspond to only one meaningful plaintext, thus allowing the determination of the key. It would also be possible to use frequency counts, though this would require much longer texts.

  2. Known plaintext: With a little luck, knowing two letters of the plaintext and the corresponding letters of the ciphertext suffices to find the key. In any case, the number of possibilities for the key is greatly reduced and a few more letters should yield the key.

    For example, suppose the plaintext starts with if and the corresponding ciphertext is PQ. In numbers, this means that 8 (=i) maps to 15 (=P) and 5 maps to 16. Therefore, we have the equations

    8α+β15and5α+β16 (mod26).

    Subtracting yields 3α125 (mod26), which has the unique solution α=17. Using the first equation, we find 817+β15 (mod26), which yields β=9.

    Suppose instead that the plaintext go corresponds to the ciphertext TH. We obtain the equations

    6α+β19and14α+β7 (mod26).

    Subtracting yields 8α12 (mod26). Since gcd(8, 26)=2, this has two solutions: α=5, 18. The corresponding values of β are both 15 (this is not a coincidence; it will always happen this way when the coefficients of α in the equations are even). So we have two candidates for the key: (5, 15) and (18, 15). However, gcd(18, 26)1 so the second is ruled out. Therefore, the key is (5, 15).

    The preceding procedure works unless the gcd we get is 13 (or 26). In this case, use another letter of the message, if available.

    If we know only one letter of plaintext, we still get a relation between α and β. For example, if we only know that g in plaintext corresponds to T in ciphertext, then we have 6α+β19 (mod26). There are 12 possibilities for α and each gives one corresponding β. Therefore, an exhaustive search through the 12 keys should yield the correct key.

  3. Chosen plaintext: Choose ab as the plaintext. The first character of the ciphertext will be α0+β=β, and the second will be α+β. Therefore, we can find the key.

  4. Chosen ciphertext: Choose AB as the ciphertext. This yields the decryption function of the form x=α1y+β1. We could solve for y and obtain the encryption key. But why bother? We have the decryption function, which is what we want.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset