Hall II · Substitution Antiquity → 1800s · math-age Trivial

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.

OriginGeneralisation of Roman shift ciphers
YearFormalised 19th c. (used informally far earlier)
Key TypePair (a,b) — a coprime to 26 → 12·26 = 312 keys
PropertyCaesar = a·1+b; Atbash = a·25+b·25
Modern LessonLinearity is fatal to security

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.

⚙️How It Works

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.

💀How It Was Broken
Brute force
Complexity: Trivial (312 keys)

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.

Frequency analysis
Complexity: Trivial (any monoalphabetic substitution)

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.

🔬What It Teaches Modern Cryptography
Affine conceptModern echo
Coprime requirement on aRSA's coprime requirement on the public exponent e
Linear transformation in mod 26The Hill cipher generalises this to matrix multiplication
Tiny key spaceThe reason modern keys are 128–256 bits, not 9 bits
Linearity = trivially invertibleModern primitives deliberately add non-linear S-boxes
Quick Facts
OriginGeneralisation of Roman shift ciphers
YearFormalised 19th c. (used informally far earlier)
Key TypePair (a,b) — a coprime to 26 → 12·26 = 312 keys
PropertyCaesar = a·1+b; Atbash = a·25+b·25
Modern LessonLinearity is fatal to security
← Previous Monoalphabetic