What is an affine cipher decoder
An affine cipher decoder undoes a two-part key. To encode, each letter number x becomes (a × x + b) mod 26, with A as 0 and Z as 25.
Key b slides the alphabet like a Caesar shift. Key a stretches it. Caesar is the affine cipher with a = 1, and Atbash is a = 25, b = 25.
Key a must share no factor with 26. Any even number or 13 sends two letters to the same place, and the message can't be read back. That leaves 12 values for a and 312 keys in all.
Pick a value for key a
Top: plain letter. Bottom: where a × x sends it, with b = 0. Gold marks a letter that lands on a spot already taken.
How to decode an affine cipher by hand
- Find the inverse of a: the number that gives 1 when multiplied by a, mod 26. For a = 5 it is 21, since 5 × 21 = 105 = 4 × 26 + 1.
- Turn each coded letter into its number y.
- Work out 21 × (y − b) mod 26.
- Turn the number back into a letter.
The player decodes RCLLA with a = 5 and b = 8.
Affine cipher examples
All three use a = 5 and b = 8, the tool's starting keys. Tap Try to load one into the decoder above.
| Coded | Plain | |
|---|---|---|
| Rclla oaplx | Hello world | |
| Qccz qc iz zrc fipg | Meet me at the park | |
| Ihhwvc qifu | Affine maps |