EN FR ES

From Caesar to Enigma: A Short History of Secret Codes

For as long as people have written messages, others have tried to read them. Every new way of hiding text has eventually met someone clever enough to uncover it.

The history of secret writing is a contest between code makers and code breakers, from a Roman general shifting letters by three to Polish and British codebreakers taking apart a German cipher machine. Here are the key ideas, and how each one was broken.

Caesar cipher wheel with an outer ring of plain letters and an inner ring shifted three places, showing VENI VIDI VICI encrypted as YHQL YLGL YLFL
Diagram: the Caesar cipher with a shift of three.

Codes and ciphers are not the same thing

Specialists separate two ideas. A cipher works on letters, replacing or moving each one by a rule and a key. A code works on meaning, swapping whole words for numbers or code words from a codebook. Many historical systems mixed the two.

Shifting letters: Caesar and Atbash

The Roman writer Suetonius tells us that Julius Caesar, in the 1st century BCE, wrote private letters by replacing each letter with the one three places further along the alphabet: D for A, E for B, and so on. This is a substitution cipher: the letters stay in place, but each is swapped for another.

Against anyone determined, it is weak: there are only 25 possible shifts, so a codebreaker can simply try them all.

An even older substitution is Atbash, from the Hebrew tradition, which reverses the alphabet: the first letter swaps with the last, the second with the second-to-last. In English terms, A becomes Z and B becomes Y, so HELLO becomes SVOOL. Atbash appears in the Hebrew Bible, where the Book of Jeremiah writes "Sheshach" for Babylon.

Scrambling the order: the Spartan scytale

A different approach keeps the letters but changes their order. This is called transposition. The classic example is the scytale of ancient Sparta: a strip of leather or parchment wound around a rod, written on along the rod's length, then unwound into a jumble of letters. Only a rod of the same thickness would line the letters up again.

The clearest description comes from Plutarch, writing centuries after the fact, and historians debate how the scytale was really used. Some think it mainly proved a message was genuine rather than hiding it. Reversing a text, as our Text Reverser does, is the simplest transposition of all, and about as secure.

Al-Kindi and the power of counting

The great weakness of simple substitution was spotted in the 9th century by Abu Yusuf al-Kindi (c. 801–873), a philosopher and scientist in Baghdad. In a manuscript on deciphering secret messages, he described what we now call frequency analysis.

Bar chart of letter frequencies in English, with E the most common at about 12.7 percent, followed by T, A, O, I and N
Diagram: approximate letter frequencies in English text.

The idea is simple. In any language, some letters are far more common than others. In English, E makes up about 12% of letters, followed by T, A, O, I and N. A substitution cipher changes what the letters look like but not how often they appear. Count the symbols in a long enough message, match the most common ones to the most common letters, and the plaintext starts to emerge. You can see the pattern in any text by pasting it into our Frequency Analyzer.

Many alphabets: Alberti, Bellaso and "Vigenère"

To beat frequency analysis, a cipher has to stop the same letter always turning into the same symbol. In Renaissance Italy, the architect and scholar Leon Battista Alberti described a cipher disk around 1467: two rings of letters, one turning inside the other, so the writer could switch to a new substitution alphabet during a message. This was the first well-documented polyalphabetic cipher in Europe.

Black-and-white drawing of Alberti cipher disk: an outer ring of capital letters and numbers 1 to 4, and an inner ring of lowercase letters that turns
Alberti's cipher disk: the outer ring stays fixed while the inner ring turns to change the alphabet. Public domain drawing, via Wikimedia Commons.

In 1553 Giovan Battista Bellaso published a practical version using a keyword. Each letter of the keyword sets a different shift, and the keyword repeats along the message.

Vigenère cipher example showing ATTACKATDAWN with the repeating keyword LEMON producing LXFOPVEFRNHR
Diagram: a keyword cipher with the keyword LEMON.

The method is now called the Vigenère cipher, after the French diplomat Blaise de Vigenère, but that is a mix-up. Vigenère published a different and stronger system, an "autokey" cipher, in 1586; Bellaso's keyword cipher was credited to him by mistake in the 19th century. For about three centuries the keyword cipher had a reputation as le chiffre indéchiffrable, "the indecipherable cipher."

It was not. The British mathematician Charles Babbage broke it around 1854 but never published his method. In 1863 the Prussian officer Friedrich Kasiski published a general attack: repeated chunks of ciphertext reveal the length of the keyword, and once you know the length, the message splits into several simple Caesar ciphers, each one open to frequency analysis.

Codebooks, kings and queens

From the 15th to the 18th century, diplomats and royal courts relied on nomenclators: a substitution cipher for ordinary letters combined with a list of symbols or numbers for common words and names. They could be strong, but only as strong as the people using them. In 1586 the letters of Mary, Queen of Scots, to the conspirators of the Babington Plot were deciphered by Thomas Phelippes, working for Queen Elizabeth I's spymaster Francis Walsingham. The evidence led to Mary's execution in 1587.

The most famous nomenclator was the Great Cipher of King Louis XIV, devised by Antoine Rossignol and his son Bonaventure. It used 587 numbers, most of which stood for syllables rather than single letters. After the Rossignols died, the method was lost, and French historians could not read many royal letters for about two centuries, until the army cryptographer Étienne Bazeries broke it around 1893.

Book ciphers and the Beale mystery

A book cipher uses a shared text as the key. Each number in the message points to a word in the book, and the first letter of that word is the letter intended. Without the right book, the numbers mean nothing. The most famous is the Beale ciphers, three number sequences in an 1885 pamphlet said to reveal buried treasure in Virginia. One of the three was solved using the U.S. Declaration of Independence as the key. The other two remain unsolved, and many researchers believe the whole story is a hoax.

Playfair: encrypting letters in pairs

In 1854 Charles Wheatstone, co-inventor of the British needle telegraph, devised a cipher that encrypts letters in pairs using a 5×5 grid built from a keyword. It is named after his friend Lord Playfair, who promoted it. Because it works on pairs, single-letter frequency analysis does not work directly. Pair frequencies still give it away, but it was quick with pencil and paper, so British forces used it in the Boer War and the First World War.

Myth check: "The first computer cracked Enigma"

Not quite. Enigma was attacked with bombes, electromechanical machines that tested rotor settings. Colossus, often called the first programmable electronic digital computer, was built at Bletchley Park in 1943–44 to attack a different German cipher, the Lorenz teleprinter cipher used by the high command.

Enigma: encryption by machine

The German engineer Arthur Scherbius patented a rotor cipher machine in 1918 and began selling the Enigma commercially in 1923. The German navy adopted a version in 1926 and the army soon after, adding a plugboard in 1928.

Diagram of the Enigma signal path from a key through the plugboard and three rotors to the reflector and back to a lamp
Diagram: the path of one key press through Enigma (simplified).
An Enigma machine in its wooden case with the lid open, showing the rotors at the top, the lampboard, the keyboard and the plugboard at the front
An Enigma machine (serial A16672): rotors at the top, then the lampboard, keyboard and plugboard. Photo: ArnoldReinhold, CC BY-SA 4.0, via Wikimedia Commons (resized).

Pressing a key sent an electric current through the plugboard, which swapped pairs of letters, then through three wired rotors, each scrambling the alphabet. A reflector sent the current back through the rotors and plugboard to light a lamp showing the cipher letter. After every key press, the first rotor stepped forward, and the others turned at intervals, so the substitution alphabet changed with every letter. In effect, Enigma was a polyalphabetic cipher with an enormous number of alphabets. For the army version, with three rotors chosen from five and ten plugboard cables, the number of possible settings was about 158 quintillion (158 followed by 18 zeros).

It also had weaknesses. Because of the reflector, no letter could ever be encrypted as itself. Operators reused predictable phrases such as weather reports and formal greetings, and procedures for setting the machine sometimes leaked patterns.

Breaking Enigma

The first breakthrough came from Poland. In late 1932 the mathematician Marian Rejewski worked out the wiring of the army Enigma's rotors using permutation theory, helped by documents obtained by French intelligence. With Jerzy Różycki and Henryk Zygalski, he went on to read German messages for years, and built a machine called the bomba to speed up the search for daily settings.

Black-and-white portrait of Marian Rejewski, a man with short dark hair and round glasses, wearing a military uniform
Marian Rejewski, the Polish mathematician who first broke Enigma, as a second lieutenant in the Polish Army in Britain, 1943–44. Photographer unknown; public domain (Poland and US), via Wikimedia Commons.

In July 1939, weeks before Germany invaded Poland, the Polish team shared everything with British and French intelligence. At Bletchley Park, north of London, Alan Turing designed a far more powerful machine, the bombe, improved by Gordon Welchman. The first bombe started work in 1940. Using guessed words in a message, called cribs, the bombes eliminated impossible settings until a few remained to test by hand. By 1945 thousands of people at Bletchley Park were turning intercepts into intelligence, codenamed Ultra.

The red-brick and stone Victorian mansion at Bletchley Park with gables, bay windows and a green copper dome
The mansion at Bletchley Park, home of Britain's wartime codebreakers and now a museum, in 2022. Photo: Vintage Fan 5678, CC BY-SA 4.0, via Wikimedia Commons (resized).
WhenMilestone
1st century BCEJulius Caesar uses a shift-of-three cipher
9th centuryAl-Kindi describes frequency analysis
c. 1467Alberti's cipher disk switches between alphabets
1553Bellaso publishes the keyword cipher later called Vigenère
1586Mary, Queen of Scots' cipher letters are read
1854Wheatstone invents Playfair; Babbage breaks Vigenère (unpublished)
1863Kasiski publishes an attack on Vigenère
c. 1893Bazeries breaks Louis XIV's Great Cipher
1918Scherbius patents the Enigma rotor machine
1932Rejewski breaks the army Enigma
1940The first British bombe goes into service

Secret codes today

Modern encryption works on the bits of digital data, using mathematics that makes guessing the key impractical even for powerful computers. It protects secure websites, banking apps and messaging services.

But the old lessons still apply. Systems fail when keys are short or predictable, when people reuse them, or when patterns leak out, which is exactly how Caesar, Vigenère and Enigma fell. That is why long, random passwords matter: try our Password Generator for one that will not fall to guessing. For another story of turning letters into signals, read the history of Morse code.

Count letters like a codebreaker

Paste any text into our free Frequency Analyzer to see which letters and words appear most often, the first step in cracking a simple substitution cipher.

Open the Frequency Analyzer →

Frequently asked questions

What is the difference between a code and a cipher?

A cipher changes individual letters by a rule and a key, such as shifting each letter by three. A code replaces whole words or phrases with numbers or code words from a codebook.

How do you break a Caesar cipher?

Try all 25 possible shifts until readable text appears, or count the letters: the most common cipher letter usually stands for E in English.

Who broke the Enigma code?

Polish mathematicians Marian Rejewski, Jerzy Różycki and Henryk Zygalski first broke it in 1932. From 1939 the work continued at Bletchley Park, where Alan Turing and Gordon Welchman designed the bombe machines used to find daily settings.

Why was the Vigenère cipher called indecipherable?

Because its repeating keyword hides single-letter frequencies, it resisted attack for about three centuries. Charles Babbage broke it around 1854, and Friedrich Kasiski published a general method in 1863.