The Affine cipher is a Substitution driven by a straight line: every letter is first stretched by a multiplier and then shifted, all inside Modular arithmetic — the arithmetic of wrapping around at 26.
Choose the key: a multiplier a and a shift b.
The multiplier must be coprime with the alphabet length: for the 26-letter alphabet that leaves twelve values (1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25). Anything sharing a factor with 26 would squash several letters onto one, and the tool refuses to build that alphabet.
Number the letters from 0 (A = 0). Encrypt letter number x into
letter number (a·x + b) mod 26.
Read the new letter off the alphabet.
With multiplier 3 and shift 7, S (letter 18) lands on (3·18 + 7) mod 26 = 9 — J. E (letter 4) lands on 19 — T. The middle column is the honest heart of the cipher: a multiplication and an addition, wrapping at 26.
encrypt: y = (a·x + b) mod 26
decrypt: x = a⁻¹·(y − b) mod 26Decryption needs the inverse of the multiplier — the number that
multiplied by a gives 1 mod 26. For a = 3 the inverse is 9, because
3·9 = 27 ≡ 1 (mod 26). Only multipliers coprime with 26 have an
inverse — which is exactly why the key space is 12 × 26 = 312 keys.
A pure shift (Caesar, a = 1) slides the alphabet but preserves
differences between letters: the pattern A-B-C is visible under any
shift. The multiplier reshapes the spacing — B is not "one step after
A" any more. Every gap changes with the multiplication, which is why
the same frequency analysis that fells Caesar needs more work here.
Type your message into the message input.
Set the multiplier in the multiplier field — try 3, a classic choice that is coprime with 26.
Set the shift in the shift field — the Caesar-style add-on, any value from 0 to 25.
Read the result in the output field. The same plaintext letter always maps to the same ciphertext letter, but the mapping is no longer a simple slide.
Paste the cryptogram into the message input and press the swap button the swap button.
Enter the same multiplier the multiplier field and shift the shift field the sender used. The tool computes the inverse multiplication for you — no modular arithmetic on your side.
Read the original message in the output field.
The Affine cipher is still a single fixed Substitution, so it falls to the classic attack — and, better, to a shortcut:
If you know two plaintext–ciphertext letter pairs, you can solve the
straight line directly: subtract the two equations to cancel b,
then divide — which means multiplying by the modular inverse — to
get a.
With a known, recover b from either pair.
Enter both numbers in the multiplier field and the shift field, switch to decrypt mode, and read the message.
No known letters? Fall back to Frequency analysis: the commonest ciphertext letter should be E (or T, or A), and each guess of a pair of candidates pins down a candidate key.
Affine is a monoalphabetic Substitution with a mathematical backbone — and the backbone is exactly what gives it away. Two known letters collapse the whole key. This page shows both routes.
Try it in the toolTwo parameters, one linear rule: y = (a·x + b) mod 26. Every letter
pair of the key lies on the same line. Two points determine a line —
so two known letter pairs determine the key.
Guess or obtain two plaintext–ciphertext pairs, say x₁ → y₁ and
x₂ → y₂.
Subtract: y₁ − y₂ ≡ a·(x₁ − x₂) (mod 26). Divide by x₁ − x₂ —
in Modular arithmetic, dividing means multiplying by the
modular inverse — to recover a.
Substitute back to recover b.
Enter the key and decrypt. Crib words like a known opening give you the pairs for free.
Without known letters, the cipher is still a fixed
Substitution: the commonest ciphertext letter corresponds to
E, the second to T or A, and each guessed correspondence is a
hypothesis about (a, b) that you can test on the next few letters.
There is no period to find, no structure beyond the mapping itself —
Frequency analysis works exactly as it did against Caesar,
only the candidate alphabets are less orderly.
The multiplier must be coprime with 26 — otherwise two plaintext letters collide onto one ciphertext letter and the message cannot be uniquely decrypted. That requirement halves the key space to 312 combos, and it is the first place a beginner meets the idea that carries modern cryptography: invertibility inside modular arithmetic. The same arithmetic, taken vastly more seriously, secures today's public-key exchanges.
Caesar's shift is the Affine cipher with a = 1. Affine adds one
multiplication, and with it the concept of a modular inverse. Keep
raising the stakes — exponentiation instead of multiplication — and
you arrive at RSA's public-key mathematics. The toy cipher and the
bank-grade system share one grammar.