Skip to content
ZeroServer.tools

Affine Cipher

Classical substitution cipher that maps each letter with y = (ax + b) mod 26.

Formula: y = (5x + 8) mod 26

Alphabet mapping (a=5, b=8)

A→I B→N C→S D→X E→C F→H G→M H→R I→W J→B K→G L→L M→Q N→V O→A P→F Q→K R→P S→U T→Z U→E V→J W→O X→T Y→Y Z→D

How the affine cipher works

The affine cipher is a classical monoalphabetic substitution cipher. Each letter is converted to a number (A=0, B=1, … Z=25), then encrypted with the formula y = (ax + b) mod 26, where a and b are secret keys. The key a must be coprime to 26 (i.e. gcd(a,26)=1) so that decryption is possible — the valid values are 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, and 25.

Decryption uses the modular inverse: x = a⁻¹(y − b) mod 26. When a=1, the affine cipher reduces to the Caesar cipher. For other classical ciphers see Vigenère Cipher and Rail Fence Cipher.

Private & free — this tool runs entirely in your browser.

Recommended: IndieKit Ship your Next.js startup in days.affiliate

Related Converters tools