Cipher methods Substitution
Affine cipher
Every letter runs through ax + b mod 26. The algebraic cousin of Caesar.
- Family :
- Substitution
- Difficulty :
- Intermediate
- Era :
- Mathematical generalization of Caesar
Also known as : affine substitution
The affine cipher generalizes Caesar (the case where a = 1) by allowing a multiplication in addition to the shift. It’s the bridge between hand cipher and algebraic cipher.
Principle
Each plaintext letter of rank x (with A = 0, B = 1, …, Z = 25) is transformed by:
C(x) = (a · x + b) mod 26
D(y) = a⁻¹ · (y − b) mod 26
The key is the pair (a, b). For the mapping to be bijective (and thus reversible), a must be coprime to 26. Allowed values are a ∈ {1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25} — that’s 12 options. b can take any value from 0 to 25.
Total valid keys: 12 × 26 = 312. Better than Caesar (25 keys), but far from secure.
Example
With (a, b) = (5, 8), encrypting CIPHERCHRONICLE:
C (2) → (5·2 + 8) mod 26 = 18 → S
I (8) → (5·8 + 8) mod 26 = 22 → W
P (15) → (5·15 + 8) mod 26 = 5 → F
H (7) → (5·7 + 8) mod 26 = 17 → R
E (4) → (5·4 + 8) mod 26 = 2 → C
Result: SWFRCPSRPAVWSLC.
Variants and special cases
- Caesar:
a = 1, only the shift varies. - Atbash:
a = 25 (≡ −1),b = 25— reverses the alphabet. - Pure multiplicative:
b = 0, only multiplication applies.
Weaknesses
The affine cipher inherits the classic two weaknesses:
- Brute force: only 312 keys, testable in seconds.
- Frequency analysis: still a monoalphabetic substitution, so the most frequent letter likely encodes
E. - Two known pairs solve it: if you guess two plaintext letters (via a common word), you get a linear system in two unknowns — and
(a, b)falls out instantly.
In CipherChronicle
The affine cipher introduces modular arithmetic into the puzzle experience. Grids built on it ask the player to spot two anchors (a short word, a proper noun) and then solve the system — a puzzle more mathematical than linguistic.
Grid
- 1
Ciphertext
A distribution that looks Caesar-ish, but shifted irregularly.
- 2
Finding two anchors
Two plain-cipher pairs are enough to solve for a and b.
- 3
Hypothesis: a = 5, b = 8
The function C(x) = (5x + 8) mod 26 matches the two known letters.
- 4
Apply the inverse
Compute a⁻¹ = 21 (modular inverse), then D(y) = 21 · (y − 8) mod 26.
- 5
Message revealed
The plaintext surfaces after applying the inverse function.