STATION 25 / FIELD MANUAL
← Back to crypto libraryAffine
Substitution
An affine cipher multiplies a letter's numeric value, then adds an offset. It is a fixed substitution, but the two numbers compactly describe the entire alphabet. Use A=0 through Z=25.
How to recognise it
Repeated letters and word patterns survive, just as with other monoalphabetic substitutions. If a simple shift fails but a mathematical key is provided, an affine mapping is a candidate. Its appearance is not distinctive on its own.
Worked example: encrypt CAT
Choose multiplier a=5 and offset b=8. Calculate c=(5p+8) modulo 26:
Letter p 5p+8 Remainder Cipher
C 2 18 18 S
A 0 8 8 I
T 19 103 25 Z
Result: SIZ
- Convert each plaintext letter to its number.
- Multiply by 5, add 8, then keep the remainder after division by 26.
- Convert 18,8,25 back to letters: SIZ.
Work backwards: decrypt SIZ
The inverse of 5 modulo 26 is 21, because 5×21=105 has remainder 1. Calculate p=21(c−8) modulo 26. For S: 21×10=210 → 2 (C). For I: 21×0=0 (A). For Z: 21×17=357 → 19 (T). Recovered message: CAT.
Conventions and common mistakes
The multiplier must be coprime to 26: valid values are 1,3,5,7,9,11,15,17,19,21,23,25. An even multiplier or 13 loses information. Ordinary division by 5 is not the modular inverse operation.
Related methods
- Caesar — The special case with multiplier one.
- Monoalphabetic substitution — The general fixed-alphabet family.
Useful desk reference
English letter frequencies — Compare symbol counts and repeated-letter patterns.