Using the affine tool
Set Multiply by and Then add, and the text on the left is enciphered as you type. Swap the boxes to decode with the same two numbers.
The multiplier is a picker rather than a number box, because only 12 of the 25 possible values work. The rest are missing for a reason, and it's the most interesting thing about this cipher.
Why only 12 multipliers
Number the letters A to Z as 0 to 25. Multiply by a, add b, and keep the remainder after dividing by 26. Decoding needs the multiplication undone, and that only works when a has a multiplicative inverse modulo 26.
26 factors into 2 and 13. Any multiplier sharing a factor with it collapses letters together. Multiply by 2 and both A and N land on 0, so the message can't be recovered. Multiply by 13 and the whole alphabet falls onto just two letters.
That leaves 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23 and 25. Twelve multipliers, 26 shifts, and 312 keys in total. A laptop tries them all faster than you can read this sentence, so the affine cipher is a teaching device rather than a lock.
The alphabet at a=5, b=8
Caesar, generalised
Set the multiplier to 1 and the affine cipher is a Caesar shift. Set it to 25 and add 25, and you get Atbash, the mirrored alphabet. Both of the classical ciphers people know best are single points inside this one formula.
That's the reason it survives in textbooks. It's the smallest cipher that needs real modular arithmetic to break, so it's where a cryptography course introduces the extended Euclidean algorithm and the idea of a multiplicative inverse. Students meet it in week one and break it in week two, usually with a frequency count that pins down two letters and solves the pair of equations from there.
Related conversions
Caesar is this cipher with the multiplier stuck at 1, and ROT13 is Caesar with the shift stuck at 13. Each step down the chain removes a key and makes the thing easier to break.
Given mystery text, the cipher identifier will try the shifted alphabets first.
Questions
What is the affine cipher?
A substitution cipher where each letter's position is multiplied by one number, added to another, and reduced modulo 26. Caesar and Atbash are both special cases of it.
Why can't I choose any multiplier?
The multiplier must share no factor with 26. Even numbers and 13 map several letters onto the same output, so the message could not be decoded.
How many affine keys are there?
312: twelve valid multipliers times 26 shifts. That's enough to be tedious by hand and trivial for a computer.
How do you break an affine cipher?
Count letter frequencies, guess that the two commonest map from E and T, and solve the two equations for the multiplier and the shift. Or try all 312 keys.



