The Affine Cipher is a type of monoalphabetic substitution cipher that combines multiplication and addition operations to transform plaintext letters into ciphertext. Each letter x in the plaintext is first converted to a numeric value, typically A=0 through Z=25, and then encrypted using the function E(x) = (ax + b) mod 26, where a and b are keys chosen such that a is coprime with 26. This combination of linear transformation and modular arithmetic ensures that each letter maps uniquely to a ciphertext letter, producing a deterministic but more complex substitution than a simple Caesar shift.
The Affine Cipher is conceptually related to the Caesar Cipher, which is a special case where a=1. By introducing the multiplicative component a, the Affine Cipher increases the total number of possible keys, improving resistance against frequency analysis compared to simpler monoalphabetic systems like the Simple Substitution Cipher. It is an elegant illustration of how basic arithmetic operations can enhance classical encryption techniques.
Affine Cipher: Encoding
To encrypt a letter, convert it to its numeric equivalent, apply the formula, then convert back to a letter. For instance, with keys a=5 and b=8, encoding the plaintext “HELLO” proceeds as follows:
Plaintext: H E L L O
Numeric: 7 4 11 11 14
Formula: E(x) = (5x + 8) mod 26
E(7) = (5*7 + 8) mod 26 = 43 mod 26 = 17 → R
E(4) = (5*4 + 8) mod 26 = 28 mod 26 = 2 → C
E(11) = (5*11 + 8) mod 26 = 63 mod 26 = 11 → L
E(11) = (5*11 + 8) mod 26 = 63 mod 26 = 11 → L
E(14) = (5*14 + 8) mod 26 = 78 mod 26 = 0 → A
Ciphertext: R C L L AThe combination of multiplication and addition ensures a more complex letter mapping than a simple shift.
Affine Cipher: Decoding
Decryption requires the modular multiplicative inverse of a modulo 26, denoted a⁻¹. The plaintext letter x is recovered from ciphertext y using D(y) = a⁻¹ (y - b) mod 26. Correct calculation of a⁻¹ is critical; without it, decryption is impossible. This reliance on modular inverses highlights a step beyond the purely additive logic of the Caesar Cipher, adding a layer of algebraic structure.
Ciphertext: R C L L A
Numeric: 17 2 11 11 0
Inverse a: a⁻¹ = 21 (since 5*21 ≡ 1 mod 26)
Formula: D(y) = 21*(y - 8) mod 26
D(17) = 21*(17-8) mod 26 = 21*9 mod 26 = 189 mod 26 = 7 → H
D(2) = 21*(2-8) mod 26 = 21*(-6) mod 26 = -126 mod 26 = 4 → E
D(11) = 21*(11-8) mod 26 = 21*3 mod 26 = 63 mod 26 = 11 → L
D(11) = 11 → L
D(0) = 21*(0-8) mod 26 = 21*(-8) mod 26 = -168 mod 26 = 14 → O
Plaintext: H E L L OAffine Cipher: Notes and Considerations
The Affine Cipher illustrates how modular arithmetic can significantly increase cipher complexity while remaining fully reversible. While it is still vulnerable to frequency analysis and modern cryptanalysis techniques, it provides a valuable example of algebraic enhancement in classical substitution ciphers. It is often studied alongside the Vigenère Cipher to contrast monoalphabetic and polyalphabetic approaches and to highlight the importance of mathematical structure in cipher design.