Leandro Junes

Affine Cipher

Transform each letter using multiplication and addition modulo 26.

With A = 0, B = 1, …, Z = 25,

Encryption E(x) = ax + b (mod 26)

Decryption D(y) = a⁻¹(y − b) (mod 26)

Calculator

—
Mode

gcd(a, 26) = 1 is required.

Key (5, 8) gcd(5, 26) = 1 5⁻¹ ≡ 21 (mod 26)

See the mapping

—
Top row plain alphabet (your input) Bottom row cipher alphabet (the output)

How your message is transformed

—

Position Input letter Number Calculation (mod 26) Result number Output letter

Position counts letters only; spaces, digits, and punctuation are not transformed and are left out of the table.

Why must gcd(a, 26) = 1?

If a is not invertible modulo 26, different plaintext letters map to the same ciphertext letter, so unique decryption is impossible. That is why the multiplier list above offers only the 12 values coprime to 26. Take the invalid value a = 2:

The same happens to every pair of letters 13 places apart, because 2 × 13 = 26 ≡ 0.

How does decryption work?

Encryption computes y = ax + b. To undo it, subtract b first, then multiply by a⁻¹, the number with a⁻¹a ≡ 1 (mod 26). With the current key:

Why isn't this just a shift?

A Caesar cipher has a = 1, so E(x) = x + b and every letter moves by the same amount. The affine cipher allows a ≠ 1: multiplication rearranges the alphabet before the shift is added, which makes it a more general monoalphabetic substitution.

What happens to letter frequencies?

The affine cipher is monoalphabetic: each plaintext letter always maps to the same ciphertext letter. The frequency counts of the message are therefore preserved, only assigned to different letters. If E is the most common letter of the message, then under this key the most common ciphertext letter is C.

Frequency Analysis

The Caesar Cipher is the special case a = 1, where E(x) = x + b (mod 26).

Frequency Analysis