Paste output from the CODEX codebook cipher app and watch how a cryptanalyst would attack it. The tool detects the format, fingerprints the cipher layer and strips a Vigenère layer when it finds one, counts the code groups, and then uses the shape of the text — what sits alone between spaces, what always comes first in a capitalised word, what always comes last before a space — to identify the few codes that shape alone gives away: the space, the capital-letter marker, the commonest punctuation mark, the word “the”, and the family of little words that come before it. Everything else needs a lever, and the lever real analysts used was the crib: a word they had reason to expect in the message. Panel 6½ lets you try that, and the worked example shows it succeeding.
Be warned up front: with no cribs the reconstruction will look thin even for a very long message. That is not a bug. The section at the bottom explains why, and the Zimmermann Telegram page shows, group by group, how analysts got past it in real life.
The worked example is a 176-word fictional dispatch encoded with the App’s built-in codebook at its default settings, homophones off, no cipher layer. After Analyze, scroll to panel 6½: the crib list is already filled with the names an analyst might expect in it. Click Attack with Cribs, then read panel 7. To check the answer, paste the same ciphertext into the App in Decode mode.
Panels 1–5 above use simple frequency counting — ranking code groups by how often they appear and matching the distribution to expected English. This works against simple substitution ciphers, but codebook ciphers (especially with homophones) are specifically designed to defeat it.
Panel 6 takes the first steps beyond counting. Without homophones it uses the shape of the text to identify the space code, the [CAP] marker, the commonest punctuation mark and the word “the” (the standalone code followed by the greatest variety of other codes), and it flags the codes that most often come right before “the” as function words without being able to name them. With homophones, a distributional clustering attack groups codes by the company they keep to find which ones are homophones of the same token. Panel 7 lets you toggle between frequency-only and context-enhanced reconstruction to see the difference, and panel 6½ is where real progress comes from.
But even context analysis is just the beginning. Historically, every major codebook system was eventually broken. Here is the full toolkit a modern cryptanalyst would bring to bear:
The single most powerful technique. If the analyst knows (or can guess) even a small fragment of the original message — a greeting, a date, a signature, a formulaic opening — they can match those words against the code groups at each position. Every confirmed match recovers codebook entries, and those entries can then be recognized wherever they appear in the rest of the message (or in other messages using the same codebook). This bootstrapping effect means a single good crib can unravel a large portion of the codebook.
This is how the British Room 40 broke German naval codes in WWI, and how Bletchley Park attacked Enigma in WWII. The principle is the same for codebooks: find something you know, and use it as a lever.
Instead of looking at each code group in isolation, analyze which groups appear next to which other groups. In English, certain word sequences are extremely common: “of the”, “in the”, “to the”, “it is”. If you have identified the code for “the” (the second most frequent group), then whatever groups appear immediately before it most often are likely “of”, “in”, and “to”. Each confirmed mapping opens up more context-based deductions.
A computer can build a co-occurrence matrix — for every pair of code groups, how often do they appear adjacent? — and compare this matrix against expected English word-pair frequencies. This is far more powerful than single-group frequency counting.
The hardest part of attacking a homophonic codebook is figuring out which code groups are homophones of each other (i.e., different codes for the same plaintext token). Panel 6 above demonstrates a basic version of this when homophones are detected. Modern approaches use distributional similarity: two groups that consistently appear in the same contexts (same neighbors, same positions in sentences) are likely homophones. Techniques include:
Once homophones are clustered, their combined frequency matches the original token frequency, and standard frequency analysis works again.
English has rigid grammatical structure. Once a few words are known, the possibilities for neighboring words are heavily constrained. “the ___ of” can only be a noun. “___ is” is likely a pronoun or short noun. A computer can use language models (even simple n-gram models) to score candidate decodings and prune impossible ones. Modern large language models make this even more powerful — they can evaluate whether a partial decoding “sounds like English” with high accuracy.
Real codebooks are used for more than one message. Each additional message using the same codebook provides more data for frequency analysis, more context for n-gram analysis, and more opportunities for cribs. Historically, codebook security depended on changing the codebook frequently — but producing and distributing new codebooks was expensive and slow, so in practice books were used for months or years, giving analysts ample material.
If null (dummy) code groups are present, they appear in the frequency distribution as a cluster of low-frequency groups with nearly identical counts — because each null code is inserted with equal probability. An analyst can identify this cluster statistically: look for a plateau in the frequency tail where 10+ groups all appear the same number of times. Once identified, filtering them out restores the original distribution and all standard techniques apply. Nulls add noise but do not change the fundamental structure of the real token frequencies.
If the analyst knows the codebook structure (vocabulary size, group length, whether homophones are used), they can use computers to search the space of possible codebooks. For CODEX specifically, the codebook is generated from a seed string and a set of configuration options. If the configuration is known (or can be guessed), the search space reduces to just the seed — and modern computers can test millions of candidate seeds per second.
Here is what the Decryptor actually does on its own. Fed 60,000 words of a novel — 180,000 code groups, no homophones, no cipher — it identified three codes with confidence: the space, “the”, and the commonest punctuation mark. It flagged twelve more codes as function words that precede “the” (they really were of, in, and, to, with, by, at, all, from, for, on, that) but could not say which was which. Three times as much text would not change that. This is the structural limit of frequency analysis against a codebook, and it is worth understanding.
A codebook cipher is not a letter substitution. The output mixes about 1,300 different symbols — whole words, three- and two-letter chunks, single letters, markers — and their frequency ranks line up with no fixed table. In one text “of” outranks “to”, in the next it does not; a letter code such as s or d (word endings the book has no chunk for) can outrank every word but “the”. The textbook rule “Nth most frequent code = Nth most frequent English word” is therefore wrong from rank two onward, and an earlier version of this page that applied it produced confident, wrong reconstructions. The Decryptor now commits only to what the structure of the text proves.
What does work is what worked in 1917: a lever. Guess a word the message must contain, find where its shape fits, and let each identified code constrain the next guess (panel 6½, and the worked example). Read more than one message in the same book, so that rare words recur. And, today, let a computer search for the assignment of codes to tokens that makes the whole text most English-like — a language-model attack this page does not attempt.
Against CODEX specifically, a modern analyst with standard tools would likely proceed as follows:
The fundamental weakness of any codebook system is that the mapping is fixed: the same plaintext token always produces codes from the same set. No matter how many homophones or cipher layers are added, this structural regularity leaks information with every message. This is why codebook ciphers were progressively abandoned in the 20th century in favor of stream and block ciphers, which produce entirely different output for every encryption even with the same key.
Disclaimer: these pages are educational demos provided as-is, with no warranty of any kind. The author is not responsible for any consequences arising from their use.
Send comments and bug reports to chris@chrisspackman.com.
Version 0.11.0 — Last updated: 2026-10-25
This page is Copyright © 2025 – 2026
Chris Spackman <chris@chrisspackman.com>.
This web site developed entirely on GNU/Linux with Free / Open
Source Software.
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.