23Language

Secret writing

A cipher hides a message by changing its letters by a rule. Turn a cipher wheel to hide a message, then break it by counting letters, count the keys, and see how a keyword hides the counts.

Slide the letters

A wheel of letters

A cipher hides a message by changing its letters by a rule. The simplest rule is to slide every letter along the alphabet by the same number of places. If the shift is 3, A becomes D, B becomes E, and so on, and the end of the alphabet wraps round to the start. This is called a Caesar cipher, after Julius Caesar, who is said to have used it.

Four tries follow. Each is a toy cipher for learning. None of them is safe to use for anything that matters. Without a script, each panel shows a worked example.

Try one

The wheel

Two rings of letters sit one inside the other. The outer ring is the message. The inner ring turns, and each letter of the message is swapped for the letter of the inner ring that sits under it. The number of places you turn it is the key.

Type a message and turn the wheel. Turn it the other way by the same amount and the secret message becomes readable again. A shift of 13 is special: doing it twice gets you back to the start, so it needs no separate way to decode.

ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ

PHHW PH DW WKH ROG EULGJH

With the wheel turned by 3, A becomes D, so MEET becomes PHHW.

Try two

Break it by counting

There are only 25 shifts, so you could try them all. There is a faster way. In English some letters are used far more than others. E is the most common, then T and A. When you shift a message, the most common letter shifts too. So the tallest bar in the cipher text gives away the key.

The chart shows how often each letter appears in the secret message, with the usual English pattern below it. Turn the guess until the two patterns line up. The idea was first written down by the scholar al-Kindi in the Arab world, in the 9th century.

PHHW PH DW WKH ROG EULGJH ZKHQ WKH EHOOV ULQJ QRRQ DQG EULQJ WKH OHWWHU ZLWK WKH UHG VHDO

PHHW PH DW WKH ROG EULGJH ZKHQ WKH EHOOV ULQJ QRRQ DQG EULQJ WKH OHWWHU ZLWK WKH UHG VHDO

The tallest bar in the secret message is H. The tallest in English is E. H is 3 places after E, so turning back by 3 gives the message: MEET ME AT THE OLD BRIDGE WHEN THE BELLS RING NOON AND BRING THE LETTER WITH THE RED SEAL

Try three

More keys

A shift cipher has only 25 keys. A harder rule is to give every letter its own partner, so A might become Q, B become X and so on. The number of ways to do that is 26 × 25 × 24 and so on down to 1, which is about 4 × 10 to the power of 26. That is far too many to try one by one.

Slide the number of guesses a computer can make each second and see how long it would take to try every key. Then remember the lesson of the last panel: counting letters still breaks this cipher, without trying the keys.

Time to try every key at different speeds
Guesses a secondShift cipher (25 keys)Every letter its own partner
1 × 10 to the power of 3less than a second6.4 × 10 to the power of 15 years
1 × 10 to the power of 6less than a second6.4 × 10 to the power of 12 years
1 × 10 to the power of 9less than a second6.4 × 10 to the power of 9 years
1 × 10 to the power of 12less than a second6.4 × 10 to the power of 6 years

At 1 billion guesses a second, trying every shift takes less than a second. Trying half of the 4.03 × 10 to the power of 26 letter arrangements, on average, takes about 6.4 billion years.

Try four

Hide the counts

A Vigenère cipher uses a keyword. The first letter of the message is shifted by the first letter of the keyword, the second by the second, and when the keyword runs out it starts again. The same letter now turns into different letters, so the letter counts are flatter and the trick of the last panel stops working.

Type a keyword and compare the chart with the one for a plain shift. For a long time this cipher was thought unbreakable. In the 1800s Charles Babbage and Friedrich Kasiski found ways to find the length of the keyword and then count letters one position at a time.

A plain shift by 3

Your keyword

After a plain shift the tallest bar is 16.3 per cent of the letters. With the keyword LEMON it is 6.7 per cent, so there is no single tall bar to point to the key.

Key takeaways

  1. A Caesar cipher slides every letter along the alphabet by the same number of places. The shift is the key.
  2. It has only 25 keys and also falls to letter counting: E is the most common English letter, so the tallest bar in the cipher text points to the shift.
  3. Letter counting was first written down by al-Kindi in the 9th century.
  4. Giving every letter its own partner makes about 4 × 10 to the power of 26 keys, too many to try, but counting letters still breaks it.
  5. A keyword (Vigenère) cipher flattens the counts by shifting by different amounts, and it held out until the 1800s.

Sources

Most of these sites could not be opened while this page was written, so the facts were checked through search results that quote them. The Caesar cipher as a shift of the alphabet, al-Kindi and letter counting in the 9th century, the Vigenère cipher as a series of shifts by the letters of a keyword, Babbage’s unpublished break around the 1840s and Kasiski’s published method in 1863, and the English letter shares (E 12.7, T 9.1, A 8.2 per cent) each appeared in at least two places. The sources differ on who first described the Vigenère cipher (Belaso in 1553, Vigenère in 1586) and on the date of Babbage’s break (1846 or 1854), so the page only says the 1800s for Babbage. The number of letter arrangements (26 factorial, about 4.03 × 10 to the power of 26) was computed. These ciphers are toys and are not safe to use.