The Dancing Men cipher from Conan Doyle's 1903 Sherlock Holmes story is a monoalphabetic substitution cipher with word-boundary flags. Holmes breaks it with frequency analysis. Here is how it works.
Arthur Conan Doyle published "The Adventure of the Dancing Men" in The Strand Magazine in 1903, and it gave the reading public one of the earliest popular depictions of cryptanalysis in fiction. The cipher at its center is a string of stick-figure drawings, each figure in a different pose, some holding flags. Holmes solves it. The story is not just good drama. The cryptography is sound.
The dancing men are a monoalphabetic substitution cipher: each figure stands for one letter of the English alphabet, and the same letter always maps to the same figure. That is exactly the class of cipher that frequency analysis breaks, and that is exactly how Holmes breaks it. Conan Doyle, whether by study or by intuition, wrote a cryptanalysis scene that holds up.
You can encode and decode messages yourself with our Dancing Men cipher tool, and the rest of this post explains the mechanism and the attack in detail.
"The Adventure of the Dancing Men" first appeared in The Strand Magazine in December 1903 and was collected in The Return of Sherlock Holmes in 1905. The plot: Hilton Cubitt of Riding Thorpe Manor in Norfolk writes to Holmes because his American wife, Elsie, is terrified by a series of chalk drawings of dancing stick figures that keep appearing around the property. Cubitt does not understand them. Elsie does, but she will not explain why.
The figures arrive in batches. Cubitt copies them faithfully and sends the copies to Holmes. Holmes recognizes them as a cipher rather than children's drawings, and he treats each batch as ciphertext. The story turns on Holmes reconstructing the key from a handful of short messages, then composing a reply in the same cipher to draw the sender out. The sender, Abe Slaney, an old associate of Elsie's from a criminal gang in Chicago, arrives, shots are exchanged, and Cubitt is killed.
The cipher itself is never printed as a single key table in the story. Conan Doyle gives the reader the figures piecemeal, through the messages Cubitt sends. Holmes reconstructs the mapping on the page, letter by letter, and the reader watches him do it. No full canonical key was published by Conan Doyle, but fans and cryptographers have since reconstructed one from the messages in the text, and it is that reconstruction that most Dancing Men cipher tools implement today. The Wikipedia article on "The Adventure of the Dancing Men" summarizes the story and the cipher's place in the Holmes canon.
Mechanically, the dancing men cipher is a monoalphabetic substitution cipher. The alphabet is the 26 letters of English. The ciphertext symbols are drawings of stick figures, each in a distinct pose: arms up, arms down, arms out, legs apart, holding a flag, and so on. One figure equals one letter. The mapping is fixed for the duration of the correspondence, which is what "monoalphabetic" means.
The clever part is the flag. Some figures hold a small flag, usually in one hand. In the story, a flag marks the end of a word. That is a word-boundary signal baked into the ciphertext itself, which is unusual. Most substitution ciphers strip word boundaries entirely, forcing the cryptanalyst to recover them from the letter stream. Conan Doyle gives his attacker a free hint: the flag tells you where one word ends and the next begins.
This matters more than it looks. Word boundaries are a major source of information for breaking substitution ciphers. If you know where the words are, you can match short words against short-word lists. A three-letter word with a repeated first and third letter is almost certainly a candidate for a small set of English words. The flags hand that information to Holmes for free.
The symbol-to-letter mapping is never given as a complete table in the story. Holmes builds it incrementally. He assigns letters to figures as he confirms them, then uses those assignments to attack the next message. This is realistic. Real cryptanalysts work exactly this way, building a partial key and extending it. You can experiment with the same mechanism on any substitution ciphertext using our substitution cipher helper, which lets you assign letters to symbols one at a time and watch the plaintext emerge.
Holmes uses frequency analysis and pattern matching. These are the standard attacks on any monoalphabetic substitution cipher, and they have been known since the 9th-century Arab scholar Al-Kindi wrote about them in A Manuscript on Deciphering Cryptographic Messages. Al-Kindi observed that in any given language, letters occur with characteristic frequencies, and in a monoalphabetic substitution the frequencies are preserved, just relabeled. The Wikipedia article on Al-Kindi covers his contribution to cryptanalysis, and the technique is documented in Simon Singh's The Code Book (1999, Fourth Estate) as the foundational break against substitution ciphers. You can read more about the technique in our frequency analysis explained post and test it directly with the letter frequency analyzer.
Holmes's attack, as Conan Doyle writes it, runs roughly like this.
First, he counts figure frequencies. E is the most common letter in English text, so the most frequent figure is a strong candidate for E. This is the single most reliable starting point for English substitution ciphers, and Holmes uses it.
Second, he uses word boundaries. The flags tell him where words end. He looks for short words. A common three-letter word ending in the candidate-for-E figure is a strong candidate for "the", which fixes T and H as well as E. Once you have T, H, and E, a large fraction of typical English text is partially readable.
Third, he uses context and guesswork. Once a few letters are fixed, partially decoded words suggest themselves, and those suggestions confirm or refute the current key assignments. Holmes guesses, checks, and extends. This is the same loop a modern solver runs, by hand or with software.
Conan Doyle has Holmes explain the process in the story, and he gets the cryptography right. The attack on a monoalphabetic substitution cipher is frequency analysis plus pattern matching plus trial, and that is what Holmes does. The flag word-boundary markers make it faster, but the core method is unchanged. The same attack breaks the Atbash cipher, the Caesar cipher, and any other fixed-substitution scheme, because all of them preserve letter frequencies.
Yes, for a monoalphabetic cipher. The dancing men cipher is weak by design, or rather by the design constraints of a detective story where the detective has to win. A monoalphabetic substitution cipher over a 26-letter alphabet has 26 factorial possible keys, which is about 4 times 10 to the 26th power. That is a large keyspace, but frequency analysis does not search the keyspace. It exploits the structure that substitution preserves, which is letter frequency and word pattern. With enough ciphertext, a monoalphabetic substitution is breakable by hand, and has been for over a thousand years.
The story's realism has two qualifications. First, Holmes works from very short messages. The batches Cubitt sends are short, and in real life short ciphertexts are harder to crack because frequency statistics are noisier. Conan Doyle helps Holmes by giving him the word-boundary flags and by having the messages contain common words like "the" and "come." Second, Holmes has contextual information the reader does not. He knows the figures are connected to Elsie's past, which narrows the subject matter and lets him guess words a pure cryptanalyst could not. Both of these are fair. A real cryptanalyst uses every available side channel, and word boundaries plus context are exactly the kind of side channel that makes a short substitution ciphertext tractable.
The cryptographic point stands. A monoalphabetic substitution cipher is broken by frequency analysis. Conan Doyle depicted that correctly in 1903, decades before the general public had any exposure to cryptanalysis. The story is one of the earliest mass-market depictions of the technique in fiction, and it is technically accurate, which is rare enough to be worth noting. Bruce Schneier's Applied Cryptography (1996, John Wiley and Sons) covers the same attack in its chapter on simple substitution, and the mechanism has not changed since Al-Kindi.
The dancing men have outlived the original story. The Granada Television series starring Jeremy Brett adapted "The Adventure of the Dancing Men" in 1984, in an episode titled "The Dancing Men," and kept the cipher central to the plot. The figures were drawn for the production, and the cryptanalysis scene was preserved.
The BBC's "Sherlock" (2010-2017) did not adapt this specific story directly, but the series drew heavily on Conan Doyle's cipher tropes, and the dancing men concept, pictograms standing in for letters, recurs across modern detective fiction and puzzle design. The idea that a set of drawings can be a cipher is now a standard device in escape rooms, CTF challenges, and puzzle hunts.
The reason the device persists is that it is visually memorable and mechanically simple. A pictographic substitution cipher is easy to draw, easy to explain, and easy to attack with frequency analysis, which makes it a good teaching cipher. If you want to build your own, the rules are: pick one symbol per letter, keep the mapping fixed, and decide whether to mark word boundaries. You can test your own messages end to end with the Dancing Men cipher tool.
It is a monoalphabetic substitution cipher from the 1903 Sherlock Holmes story 'The Adventure of the Dancing Men.' Each stick-figure drawing stands for one letter of the English alphabet, and figures holding flags mark the ends of words. Holmes breaks it using frequency analysis.
He used frequency analysis and pattern matching. The most common figure was a candidate for E, the most common English letter. Word-boundary flags let him identify short words, and a common three-letter word ending in E was a candidate for 'the,' which fixed T and H. He then extended the key by guessing words from context.
The specific drawings are fictional, but the cipher type is real. It is a monoalphabetic substitution cipher, a class that has been used historically and is breakable by frequency analysis, a technique documented by the 9th-century scholar Al-Kindi. Conan Doyle's depiction of the attack is technically accurate.
No. Conan Doyle never published a complete symbol-to-letter key. The mapping is revealed piecemeal through the messages in the story, and Holmes reconstructs it on the page. Fans and cryptographers have since reconstructed a full key from the messages, and that reconstruction is what most Dancing Men cipher tools use.
A figure holding a flag marks the end of a word. This is a word-boundary signal embedded in the ciphertext itself. Most substitution ciphers strip word boundaries, so the flags give the cryptanalyst extra information that makes the cipher easier to break.
Dancing Men Cipher
Encode and decode the Dancing Men cipher from Arthur Conan Doyle's 1903 Sherlock Holmes story, a pictographic monoalphabetic substitution of stick-figure symbols.
Letter Frequency Analyzer
Count and analyze letter frequencies in text for cryptogram solving.
Substitution Cipher Helper
Tools and utilities for solving substitution cipher puzzles.
Frequency Analysis Explained: How to Break Any Substitution Cipher
Al-Kindi discovered frequency analysis in 9th-century Baghdad. The technique still breaks CTF substitution ciphers today. Here is how it works and how to apply it.
The Atbash Cipher: 2,500-Year-Old Encryption Still Used in Puzzles
The Atbash cipher is 2,500 years old, appears in the Hebrew Bible, and is self-inverse. It has no key space and zero security. Here is why it still matters.