Skip to content
CryptographyInternals

Keyword substitution

Scramble the alphabet with a keyword and swap each letter for its partner.

Family
Monoalphabetic substitution
Era
Antiquity to the Renaissance
Keys
26! ≈ 4 × 10²⁶ alphabets

A general substitution cipher replaces each letter with another according to any permutation of the alphabet. A keyword makes that permutation easy to remember and share.

With about 4 × 10²⁶ possible alphabets, trying every key is out of the question. Arab scholar al-Kindi still showed how to break it in the 9th century.

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

01 / 11 · Inside keyword substitution

A message to hide

This readable text is the plaintext. Encrypting turns it into ciphertext. Classical ciphers only touch letters.

The goal: whoever intercepts the ciphertext must not get back to these letters.

Playground

Build your own cipher alphabet

Pick a keyword: it opens the cipher alphabet, the rest of the alphabet follows. Then step through your message letter by letter.

Your input

Repeated letters are dropped; only A–Z count.

Result
from the keywordrest of the alphabet
Input
Output

Encrypt

Open the alphabet with ZEBRAS

What happens

Write the keyword first, then every letter not used yet, in order. Each plain letter gets the cipher letter written under it.

On your values

ZEBRAS + CDFGHIJKLMNOPQTUVWXY

A→Z B→E C→B …

Why it matters

Any shuffle of the alphabet is a key: 26! ≈ 4 × 10²⁶ of them, far too many to try. Yet each letter always gets the same partner, so the letter frequencies of the language pass straight through (see below).

Spaces, digits and punctuation pass through unchanged; accents are dropped.

Start

How it’s broken

Frequency analysis: count, rank, match

26! keys are too many to try, so the attacker counts letters instead. Rank the ciphertext’s letters by count and line them up with English’s ranking: the top guesses are often right, and word patterns (THE, AND…) fix the rest. Al-Kindi described the method in the 9th century.

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

Ciphertext with the 7 ranking guesses filled in (· = not guessed yet)

ETTEAO ET NESI

ciphercountguessactual
Z33.3%EA ✗
Q25.0%T ✓
B8.3%AC ✗
H8.3%OK ✗
K8.3%IN ✗
R8.3%ND ✗
V8.3%SW ✗

1 of 7 guesses right from counting alone.

Short texts can fool the statistics: the longer the ciphertext, the surer the attack. Try the long-text preset.

How it works

  1. 1Write the keyword's letters, dropping any that repeat.
  2. 2Append the rest of the alphabet in order, skipping letters already used. This is the cipher alphabet.
  3. 3Replace each plaintext letter with the cipher letter in the same position.
  4. 4To decrypt, find the letter in the cipher alphabet and read the plain letter above it.

How it is broken

Frequency analysis: in English, E, T and A are the most common letters, and their substitutes stand out in any ciphertext of reasonable length.

Common short words and letter pairs (THE, AND, TH, HE) give away more of the mapping, one guess at a time.

Keyword alphabets add another weakness: the end of the cipher alphabet is often left almost in order.

Read the in-depth articleHow to Crack a Caesar Cipher and Break VigenèreA hands-on cryptanalysis tutorial: crack a Caesar cipher by brute force and frequency analysis, then break Vigenère with Kasiski to recover the key LEMON.