Affine cipher
The affine cipher turns letters into numbers, multiplies them, adds a constant, and wraps the result back into the alphabet. It's a small step of maths beyond the Caesar shift, and a great introduction to how ciphers use arithmetic.
The idea
Number the alphabet from A = 0 to Z = 25. The affine cipher uses two key numbers, a and b, and turns each letter x into (a × x + b) mod 26: multiply, add, then keep the remainder after dividing by 26. The Caesar cipher is the special case a = 1. Another ancient cipher, Atbash, which reverses the alphabet (A↔Z, B↔Y), is the case a = 25, b = 25.
How it works
| Letter | Number | a×x+b | mod 26 | Cipher |
|---|---|---|---|---|
| S | 18 | 5×18+8 = 98 | 20 | U |
| P | 15 | 5×15+8 = 83 | 5 | F |
| I | 8 | 5×8+8 = 48 | 22 | W |
| E | 4 | 5×4+8 = 28 | 2 | C |
| S | 18 | 5×18+8 = 98 | 20 | U |
SPIESUFWCUWhy only some multipliers work
For the cipher to be reversible, no two letters may land on the same result. That only happens when a shares no factor with 26, so a must be odd and not 13. That leaves 12 choices: 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23 and 25. With 26 choices for b, there are 312 keys in all. Try a = 2 and you'll see A and N both become the same letter.
How to crack it
312 keys is few enough to try them all with a computer. By hand, two known letters are enough: if you know which cipher letters two message letters became, you get two simple equations and can solve for a and b. In a longer message, letter counting gives you those two letters: the most common cipher letter is probably E, the next probably T.
Affine in Cyrune
Each letter always becomes the same letter, so repeated lamps mean repeated letters. Two green tiles with different letters are enough to work out both numbers; then set the two rotors to match. Cyrune rates it four stars because the multiplier hides the neat alphabet order you'd see in a shift.
Related ciphers
- Shift cipher ★☆☆☆☆
- Substitution cipher ★★★★☆
- Keyword cipher ★★★★☆