Substitution cipher
monoalphabetic
Every letter has one fixed substitute. There are over 4·10²⁶ keys, and the cipher still falls, because letter frequency gives it away.
- Made
- antiquity — no single inventor or date
- Broken
- 9th c., Baghdad — al-Kindi, the oldest surviving description of frequency analysis
- How it works
- every letter has one fixed substitute
- Today
- AES: rounds and modes of operation
- Sources
Substitution table
A substitution cipher replaces every letter with its substitute. The substitute is fixed: the same plaintext letter gives the same ciphertext letter all through the text. The key is the whole table, that is, the 26 letters set in a new order (a permutation). There are 26! ≈ 4.03·10²⁶ such orders.
The Caesar cipher is a special case: a table where every substitute stands the same number of places on. The “Set Caesar +3” button does exactly that. Any other table is a key too, as long as no letter repeats among the substitutes.
The replica below has the 26 letters of today’s Latin alphabet. Substitution ciphers were written in various alphabets, and al-Kindi worked on Arabic text (see Context).
Substitution table
The table has the 26 letters of today’s Latin alphabet. Polish letters lose their marks (ś → S); digits and other characters pass through unchanged.
Or tap two columns of the table.
Under each plain letter stands its substitute, the same all through the text. Change the key and watch the ciphertext change.
Pplaintext MEET ME AT THE BRIDGE AT FIVE
Cciphertext DTTZ DT QZ ZIT WKORUT QZ YOCT
Possible keys: 26! ≈ 4.03·10²⁶
Counting letters instead of trying keys
You cannot try every key here: 4·10²⁶ attempts are too many. The attack goes round the keys. A key changes letters but not how many there are: if E makes up about 12% of a text, so does its substitute. It is enough to count the letters of the ciphertext and compare them with how often letters occur in the language.
You do it in four steps. The first is counting. The second puts the ciphertext letters in order of frequency and sets the language’s letters under them in the same order. That ranking gives a starting point, not a result: in English T, A, O, I and N all stand at 7–9%, so the ranking confuses them. The third step is reading words and correcting letters one at a time. The fourth is the check: the text counts as broken when at least 90% of the letters stand right, and the page fills in the rare letters.
The passage has 300–450 letters, because a shorter text has no stable frequencies. It comes from public-domain novels, and the English frequency table from the same novels (the list of texts and the script are in the repository). The bars are not al-Kindi’s tool, only today’s way of showing what he did.
Frequency analysis
Ciphertext intercepted. First count the letters: in every language some letters are more frequent than others.
Count the letters
simplificationWe keep the spaces between words: words are easier to recognise.
What we know about al-Kindi
Al-Kindi (Abū Yūsuf Yaʿqūb ibn Isḥāq al-Kindī) lived from about 800 to about 870. He was educated and worked in Baghdad, at the court of the caliphs (Adamson, Stanford Encyclopedia of Philosophy). Where exactly he wrote his treatise on ciphers is not known, so “Baghdad” on the timeline is a convention, and the treatise cannot be dated more closely than “9th c.”.
His treatise on decrypting encrypted messages is the oldest surviving text on cryptanalysis (Al-Suwaiyel 2018):
Among those manuscripts is the oldest existing cryptologic text written by Ya‘qub ibn Ishaq al-Kindi […], titled Risalah fi Istikhraj al Mu’amma (Treatise on Decrypting Cryptographic Messages).
Al-Kindi counted letter frequencies in a sample of Arabic text and described, on that basis, how to break a substitution. The technique was later named frequency analysis (Al-Suwaiyel 2018, slides).
The manuscripts of Arabic cryptology were found from 1979 by a team of the Arab Academy of Damascus in archives in Istanbul. They were published in Arabic in 1987 and in English from 2003. Older books on the history of ciphers leave the treatise out: in 1967, when David Kahn’s The Codebreakers appeared, it was still unknown (Al-Suwaiyel 2018, slides).
Hence the popular myth that frequency analysis was invented in Renaissance Europe. The oldest surviving description is from the 9th century, in al-Kindi’s treatise.
The same pattern today
The same letter always gives the same symbol, so letter frequencies and the layout of the text carry over into the ciphertext.
ECB mode encrypts each block on its own: identical blocks give identical ciphertext, so an encrypted picture still shows the penguin.
See it in the station: AES: rounds and modes of operation →