Leandro Junes

Substitution Cipher

Replace each plaintext letter with a unique ciphertext letter.

With A = 0, B = 1, …, Z = 25, and π a permutation of the alphabet,

Encryption E(P) = π(P)

Decryption D(C) = π⁻¹(C)

Calculator

—
Mode
Key tools

A keyed alphabet uses the keyword's unique letters, then appends the unused letters. This is still one fixed substitution, not a Vigenère key.

See the mapping

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

Edit the cipher row to change the key. A letter typed into a cell trades places with the cell that held it, so the key stays one-to-one.

How your message is transformed

—
Position Input Mapping Output

Position counts letters only; spaces, digits, and punctuation are not transformed and are left out of the table. There is no arithmetic here: each letter is simply looked up in the key.

Why must the key be a permutation?

Every plaintext letter must map to exactly one ciphertext letter, and every ciphertext letter must come from exactly one plaintext letter. Otherwise the message could not be decrypted uniquely.

A → Q
B → Q
Then a ciphertext Q could mean A or B, and some other letter would have no plaintext at all.

That is why the key editor swaps letters instead of letting one appear twice.

How large is the key space?

There are 26! = 403,291,461,126,605,635,584,000,000 ≈ 4.03 × 10²⁶ possible keys: 26 choices for A, 25 left for B, and so on. Trying every key is not practical; at a billion keys a second it would take about thirteen billion years.

A substitution cipher is weak all the same, because it is attacked without trying keys one by one: with language statistics, frequency analysis, repeated-letter patterns in words, and heuristic search that improves a guessed key step by step. That is what Break mode does.

Why does frequency analysis work?

A substitution cipher is monoalphabetic: every occurrence of a plaintext letter becomes the same ciphertext letter. The letter counts of the message are therefore preserved, only attached to different letters. If E occurs 15 times and E → T, then T occurs 15 times in the ciphertext, and English has a very uneven and well-known letter distribution to compare it with.

Frequency Analysis

The Caesar Cipher and the Affine Cipher are special, structured monoalphabetic substitutions: their cipher alphabets come from a formula with one or two numbers. A general substitution cipher allows any permutation of the alphabet.

The Vigenère Cipher is different in kind: it is polyalphabetic, so the same plaintext letter can become different ciphertext letters.

Frequency Analysis