Happy Thanksgiving from the Portal. The Gathering, a harvest cipher maze, is free to play until 30 November. Enter The Gathering

Cipher Storm: practise affine ciphers against the clock. Encrypted words fall; crack the key and type them before they land. They turn up in the Elite Advanced mode.Play β†’
Free Tool

Affine Cipher Tool

Encrypt, decrypt and crack the affine cipher

a must share no factor with 26, so only these 12 work. a = 1 is a plain Caesar shift.
Plaintext

Plain
Cipher

Crack an affine cipher

Don't know the key? Paste the ciphertext above (in Decrypt mode), then use one of these.

Two-letter solver

Two letter pairs fix the key. Guess what two cipher letters stand for: start with the most common cipher letter as E and the next as T. If the preview is gibberish, try E with A, O, I or N for the second.

Try every key

There are only 12 Γ— 26 = 312 affine keys, so a computer can try them all. These are the five whose output looks most like English letter frequencies. Short messages can fool it.

How the affine cipher works

The affine cipher turns each letter into a number (A = 0, B = 1 … Z = 25), multiplies it by a, adds b, and wraps around the alphabet:

E(x) = (aΒ·x + b) mod 26

To decrypt, you undo both steps. Subtract b, then multiply by the inverse of a: the number that multiplied by a gives 1 (mod 26). For a = 5 the inverse is 21, because 5 Γ— 21 = 105 = 4 Γ— 26 + 1.

D(y) = a⁻¹·(y βˆ’ b) mod 26

Only 12 values of a have an inverse: 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23 and 25. Any even number, or 13, would send two letters to the same place, so the message could not be read back.

Example

With a = 5 and b = 8, the letter H (7) becomes 5 Γ— 7 + 8 = 43, and 43 mod 26 = 17, which is R. So HELLO becomes RCLLA.

Why it is easy to break

Every letter always turns into the same cipher letter, so letter frequency survives. The most common cipher letter is probably E, and once two letters are pinned down the key is fixed. Caesar shifts (a = 1) and the Atbash mirror (a = 25, b = 25) are both special cases of the affine cipher.

Related tools