Affine Cipher E(x) = a·x + b mod 26
A single linear formula generalises Caesar, Atbash, and ROT13 — and is broken by counting how often E appears.
Why This Matters
The affine cipher does not have a single named inventor. It is the natural mathematical generalisation of every shift-style cipher humans have improvised since antiquity: pick a multiplier a, pick an offset b, and replace each letter x with a·x+b mod 26. Caesar is the special case a=1; Atbash is a=25, b=25; ROT13 is a=1, b=13. Once nineteenth-century mathematicians wrote cryptography in algebraic notation, all of these collapsed into one formula.
The affine cipher is mostly a teaching cipher today. It is the smallest cipher whose key has more than one component, which makes it the cleanest place to introduce the ideas of key space, modular inverses, and the requirement that a and 26 be coprime.
Number the alphabet A=0, B=1, …, Z=25. Pick two integers a and b. Encryption is
E(x) = (a·x + b) mod 26
Decryption uses the modular inverse of a:
D(y) = a⁻¹·(y - b) mod 26
Critical constraint: a must be coprime to 26 (no shared factor with 26 = 2·13). Only twelve values of a qualify: 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25. Pair each with one of 26 offsets and you get 12·26 = 312 keys — small enough to brute-force by hand.
Try all 312 (a, b) pairs and pick the decryption that looks like English. A modern laptop does this in microseconds; an attentive teenager does it in an afternoon.
Affine is a monoalphabetic substitution: each plaintext letter always maps to the same ciphertext letter. Letter frequencies survive intact, so the methods al-Kindi described in the ninth century apply unchanged.
| Affine concept | Modern echo |
|---|---|
| Coprime requirement on a | RSA's coprime requirement on the public exponent e |
| Linear transformation in mod 26 | The Hill cipher generalises this to matrix multiplication |
| Tiny key space | The reason modern keys are 128–256 bits, not 9 bits |
| Linearity = trivially invertible | Modern primitives deliberately add non-linear S-boxes |
| Origin | Generalisation of Roman shift ciphers |
| Year | Formalised 19th c. (used informally far earlier) |
| Key Type | Pair (a,b) — a coprime to 26 → 12·26 = 312 keys |
| Property | Caesar = a·1+b; Atbash = a·25+b·25 |
| Modern Lesson | Linearity is fatal to security |