The Affine cipher is a Caesar cipher with a stretch. Give every letter a number (A = 0, B = 1, up to Z = 25), multiply by a secret number a, add a secret number b, then wrap around at 26 the way a clock wraps at 12. The name comes from maths: an affine function is a straight line, y = ax + b, and that is exactly the recipe.


How it works
The b is a Caesar-style shift. The a spreads the letters out so they no longer sit side by side. Try a = 5 and b = 8. A is 0, and 0 × 5 + 8 = 8, which is I. B is 1, and 1 × 5 + 8 = 13, which is N. Each next letter jumps 5 further along, so the whole cipher alphabet is:
Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Cipher: INSXCHMRWBGLQVAFKPUZEJOTYD
For a bigger letter, wrap by taking away 26 until you are back in range. M is 12, and 12 × 5 + 8 = 68, which wraps to 16, a Q. So MEET ME AT NOON becomes QCCZ QC IZ VAAV. Once the cipher alphabet is written out, Affine is a plain letter swap, just like an Aristocrat.
Why only some values of a work
The shift b can be anything from 0 to 25. But a must have no factor in common with 26, otherwise two letters would land on the same cipher letter and decoding would be ambiguous. That leaves 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23 and 25. In the app, a is never 1, because a = 1 would just be a Caesar.
Decoding
Because the puzzle hands you a and b, you can decode right away. Two good methods:
- Build the cipher alphabet. Write A to Z, put the letter numbered b under A, then step forward a places for each next letter. Check that all 26 cipher letters are different: a repeat means a counting slip. This is best for a long quote.
- Use the inverse. Take away b, multiply by the inverse of a, then wrap. With a = 5 the inverse is 21. To decode Q (16): 16 − 8 = 8, then 8 × 21 = 168, and 168 − 6 × 26 = 12, which is M.
One surprise: unlike an Aristocrat, an Affine letter can encrypt to itself. With a = 5 and b = 8, L stays L, so do not rule out a guess just because the cipher and plain letter match.
The card at the top of each puzzle shows the speaker and the keys, for example Decode the Affine Cipher with a=17 and b=21. There is no helper table under the board, so build the cipher alphabet on paper or decode with the inverse in your head. In Options you can switch Show letter frequencies, Highlight frequencies, Highlight multiple letters, Highlight errors when complete and Auto fill letters on or off. Turn on the frequencies to practise finding the likely E and T, then turn them off to solve like a competitor. Use Print / share for a paper worksheet (the printed page includes the a and b line).
When nobody gives you a and b
Suppose you only know that E becomes C and T becomes Z. Then 4a + b = 2 and 19a + b = 25. Subtract the first from the second and b disappears: 15a = 23. The inverse of 15 is 7, so a = 23 × 7 = 161, which wraps to 5. Then 4 × 5 + b = 2 gives b = −18, which wraps to 8. You have recovered a = 5, b = 8. If the plain letters' gap is even, there is no inverse, so just test the twelve allowed values of a.
Science Olympiad Codebusters
Affine is not on the 2027 Codebusters list for Division C, but it has been on tests in earlier seasons, so check the rules for your own year and division. It comes in two forms: a decode that gives you a and b, and a cryptanalysis that gives you two plain letters instead. Practise the harder form by covering the a and b line and switching on Show letter frequencies. Guess E and T from the two most common cipher letters, solve for a and b, then uncover the line to check. See Codebusters practice for more.
Practise the numbers
In Reference & Flashcards, the Letters & Numbers deck drills A = 0 up to Z = 25, the numbers the whole cipher runs on. Choose Flashcards (tap to flip, swipe right for Know and left for Still learning) or the multiple-choice Test. And once you know it, a fun fact: Caesar and Atbash are secretly Affine ciphers. Caesar has a = 1, and Atbash is a = 25, b = 25.


