Old ciphers, and how counting letters breaks them
Every cipher, old or new, does two things to a message: it swaps symbols for other symbols, and it moves symbols around. The pencil-and-paper ciphers show both moves plainly, and they show the oldest way of breaking a cipher, which is to count letters. No background is assumed. Modern ciphers are built to defeat exactly the attack described here, so the names from this history are still the names in use.
By the end of this unit you will be able to:
- Tell apart a substitution cipher and a transposition cipher
- Explain how frequency analysis breaks a substitution cipher, and work a short case
- Explain what a ciphertext-only attack is and why it is the hardest position for an attacker
- Explain the four conditions that make a one-time pad unbreakable
- Tell apart a stream cipher and a block cipher
A note pinned to the staff-room board
An illustrative example
A school caretaker leaves coded notes for the deputy head about where the spare keys are hidden. Each letter is moved three places along the alphabet. The two of them think the notes are safe, because the alphabet could have been moved by any amount and nobody else knows which.
A sixth-former copies one note from the board: WKH NHBV DUH EHQHDWK WKH JUHHQ VHDW EB WKH JDWH. She has no idea of the method. She counts how often each letter appears, and ten minutes later she is reading the note aloud.
What did counting the letters tell her that the scrambling was meant to hide?
Substitution: swapping each letter for another
A substitution cipher replaces each letter of the with a different letter or symbol. The letters stay in their original order.
The Caesar cipher is the simplest kind. Every letter is moved the same number of places along the alphabet, and that number is the key. With a key of 3, A becomes D and THE becomes WKH. There are only 25 useful keys, so trying them all takes minutes.
A general uses a fully mixed alphabet as its key: A might become Q, B might become F, and so on. The key space is enormous, about 4 followed by 26 zeros. The is still weak, because each plaintext letter always becomes the same letter. That pattern survives the scrambling.
The Vigenère cipher hides the pattern by using several alphabets in turn. A keyword sets the shifts: with the keyword BAD the first letter moves 1 place, the second 0, the third 3, then the cycle repeats. The plaintext EEEEEE becomes FEHFEH. One plaintext letter now has several ciphertext forms. A cipher that does this is called polyalphabetic.
- Code
- A code replaces whole words or phrases using a codebook: "the eagle has landed" for "the delivery arrived". A cipher works on single letters or bits and needs no codebook.
- Steganography
- Steganography hides the existence of a message, for example inside the data of a picture file. hides the meaning of a message that anyone can see is there.
Transposition: shuffling the letters
A transposition cipher keeps every letter and changes their order. Write MEETATNOON by placing the letters alternately on two lines, then read the top line followed by the bottom line. The result is MEANOETTON. Every original letter is still there.
| Point | Substitution | Transposition |
|---|---|---|
| What changes | Which letters appear | The order of the letters |
| What stays | The order of the letters | Which letters appear, and how often |
| Example | THE becomes WKH | MEETATNOON becomes MEANOETTON |
| Property it gives | Confusion | Diffusion |
Claude Shannon gave the two effects their names in 1949. Confusion makes the link between the key and the ciphertext too complicated to work back from. Diffusion spreads the influence of each piece of plaintext across much of the ciphertext, so that patterns in the message are smeared out. A modern cipher applies substitution and over and over to get both.
Frequency analysis: counting letters
In any language some letters are used far more than others. In a very large sample of English, E makes up about 12.5% of all letters, T about 9.3% and A about 8.0%. Z, Q, J and X are each well under 1%.
Frequency analysis breaks a cipher by counting how often each symbol appears in the ciphertext and matching the counts to the known habits of the language. The most common ciphertext letter probably stands for E. A common three-letter group probably stands for THE. Each guess that fits confirms the others.
- It defeats simple substitution ciphers, however large their key space, because each plaintext letter always maps to the same ciphertext letter.
- It is slowed by polyalphabetic ciphers such as Vigenère, which flatten the counts. A repeating keyword still leaves a pattern that a longer analysis finds.
- It gains nothing against a modern cipher, whose ciphertext shows no usable pattern at all.
Common misconception
“A cipher with billions of billions of possible keys must be safe.”
A large key space only defeats brute force. Simple substitution has a vast key space and falls in minutes to letter counting. A cipher must also leave no pattern for an attacker to use.
Ciphertext only: the attacker's weakest starting point
Attacks on a cipher are sorted by what the attacker holds at the start. In a ciphertext-only attack the attacker holds nothing except ciphertext. There is no sample of the matching plaintext and no access to the system that did the .
The attacker has the least to work with, so this is the hardest attack to carry out. It is also the easiest position to reach. Anyone who can copy a note from a board, or record traffic on a network, holds ciphertext.
The sixth-former's letter count is a ciphertext-only attack. A cipher that falls to one is very weak, because every cipher in use gives its opponents this much. Stronger starting positions exist, in which the attacker also holds some plaintext that matches the ciphertext.
Ciphertext only describes what the attacker holds. Frequency analysis and brute force describe what the attacker does with it.
The one-time pad: unbreakable, and rarely practical
A one-time pad is a cipher in which the key is a string of random values exactly as long as the message. It is also called the Vernam cipher, after Gilbert Vernam, who patented the machine version in 1919. Each piece of the message is combined with the matching piece of the key, and that part of the key is never used again. Shannon proved that such a cipher cannot be broken, however much computing power the attacker has.
The proof holds only while four conditions all hold.
- The key is truly random.
- The key is at least as long as the message.
- The key is used once and then destroyed.
- The key is kept secret, and reaches both parties by a secure route.
Computers combine message and key with exclusive or (XOR), a rule applied bit by bit: two bits that match give 0 and two bits that differ give 1. The message bits 0110 combined with the key bits 1010 give 1100. Combining 1100 with the same key gives 0110 again, which is how the recipient .
The cost is the key. Protecting a 1 gigabyte file needs 1 gigabyte of delivered safely beforehand. A pad used twice is no longer unbreakable, because the two ciphertexts can be compared.
Stream ciphers and block ciphers
Modern ciphers that share one key between sender and recipient come in two kinds.
A stream cipher encrypts data one bit or one byte at a time. It uses a short key to generate a long run of unpredictable bits called a keystream, and combines the keystream with the plaintext by XOR. It copies the working of a one-time pad, but its keystream is calculated from a short key, so the proof of unbreakability does not apply.
A block cipher cuts the data into fixed-size pieces called blocks, commonly 64 or 128 bits, and encrypts one whole block at a time.
| Point | Stream cipher | Block cipher |
|---|---|---|
| Works on | One bit or byte at a time | A fixed block, such as 128 bits |
| Method | XOR with a generated keystream | Rounds of substitution and transposition on the block |
| Suited to | Continuous data such as voice, and simple hardware | Files, databases and most general use |
| Main danger | Reusing the same keystream | Using the block cipher in a weak mode |
| Example | RC4 | AES |
Worked example: Breaking the caretaker's note by counting
The ciphertext is WKH NHBV DUH EHQHDWK WKH JUHHQ VHDW EB WKH JDWH. It has 38 letters. Nothing else is known.
- Count each letter. H appears 11 times, W 6 times, K 4 times and D 4 times. Every other letter appears twice or less.
- E is the most common letter in English, so guess that H stands for E. H is three places after E in the alphabet.
- The group WKH appears three times, and a common three-letter group probably stands for THE. If WKH is THE, then W stands for T and K stands for H. Each is again three places along, which fits the first guess.
- Test the idea that every letter has been moved three places. Move each ciphertext letter three places back: W to T, K to H, H to E, N to K, and so on.
- The result reads THE KEYS ARE BENEATH THE GREEN SEAT BY THE GATE.
The key, a shift of 3, was found from the ciphertext alone. Two guesses from the letter counts were enough, and the third confirmed them.
A question, worked through
A security analyst at a logistics firm reviews an old handheld scanner system that is due for replacement. It protects delivery records with a cipher designed in-house years ago, in which each character is always replaced by the same other character. The vendor points out that the number of possible keys is far beyond what any computer could try. Scanner traffic can be recorded by anyone in the depot car park.
Which attack is the MOST likely to succeed against this system?
Decide on your answer, then open the reasoning
- The question asks which attack fits the weakness described. The decisive facts are that each character always maps to the same character and that an outsider can collect ciphertext.
- Rule out d. Transposition is a way of building a cipher. It is not an attack.
- Rule out c. A one-time pad is a kind of cipher, and this system is not one. Long use of one key is a fault, but it does not name an attack.
- Between a and b: the vendor is right that the key space is too large for brute force, so a fails on the facts given.
- A fixed mapping keeps the letter patterns of the plaintext, and the attacker needs only ciphertext. That is frequency analysis, option b.
Answer: B. Frequency analysis, because repeated characters keep the patterns of the records
Choosing between good answers
- A scenario says each letter or character is always replaced by the same symbol
- the weakness is to frequency analysis, whatever the size of the key space.
- A question asks which attack needs the least from the attacker
- choose ciphertext only: the attacker holds intercepted ciphertext and nothing else.
- An option claims a cipher is unbreakable
- accept it only for a one-time pad, and only if the key is random, as long as the message, never reused and kept secret.
- A question asks whether letters were swapped or shuffled
- swapped letters in the same order is substitution. The same letters in a new order is transposition.
Check your understanding
4 questions on this unit, easiest first. Confirm an answer to see the reasoning for it, then the right answer, the other options and the rule to reuse. Your answers are kept in this browser and feed readiness and review.
These questions are drafts that no named reviewer has approved yet.
Question 1 of 4
What to remember
- Substitution replaces letters and keeps their order. Transposition keeps the letters and changes their order.
- Frequency analysis breaks simple substitution by matching letter counts to the language. E is the most common letter in English.
- In a ciphertext-only attack the attacker holds only ciphertext. It is the hardest attack to carry out and the easiest position to reach.
- A one-time pad is unbreakable only with a random key as long as the message, used once and kept secret.
- A stream cipher encrypts bit by bit with a keystream. A block cipher encrypts fixed-size blocks.
- A large key space does not make a cipher strong if the ciphertext still shows a pattern.
Say it from memory
What does the attacker hold in a ciphertext-only attack, and how hard is the attack?
Only intercepted ciphertext: no matching plaintext and no access to the encrypting system. It gives the attacker the least to work with, so it is the hardest attack to carry out, but it is the easiest position to reach. Frequency analysis of a substitution cipher is the classic example.
How does frequency analysis break a cipher, and which ciphers does it defeat?
It counts how often each symbol appears in the ciphertext and matches the counts to the language: the most common letter probably stands for E, and a common three-letter group probably stands for THE. It defeats simple substitution ciphers, is slowed by polyalphabetic ciphers such as Vigenère, and gains nothing against modern ciphers.
How does the Vigenère cipher differ from the Caesar cipher, and what does polyalphabetic mean?
The Caesar cipher moves every letter the same number of places, and that number is the key, so there are only 25 useful keys. Vigenère uses a keyword to set a different shift for each letter in turn. Polyalphabetic means one plaintext letter has several ciphertext forms.
How does transposition differ from substitution, and what do confusion and diffusion mean?
Substitution changes which letters appear and keeps their order; it gives confusion. Transposition changes the order of the letters and keeps which letters appear; it gives diffusion. Confusion makes the link between key and ciphertext too complicated to work back from. Diffusion spreads each piece of plaintext across much of the ciphertext.
What four conditions make a one-time pad unbreakable?
The key is truly random. The key is at least as long as the message. The key is used once and then destroyed. The key is kept secret and reaches both parties by a secure route.
How does a stream cipher differ from a block cipher, and what is the main danger of each?
A stream cipher encrypts one bit or byte at a time by XOR with a keystream generated from a short key, as RC4 does; its main danger is reusing the same keystream. A block cipher encrypts a fixed block, such as 128 bits, at a time, as AES does; its main danger is use in a weak mode.
Sources
- English Letter Frequency Counts: Mayzner Revisited, Peter NorvigThe share of each letter in a very large sample of English: E about 12.5%, T about 9.3%, A about 8.0%, and Z, Q, J and X each under 1%.
- Communication Theory of Secrecy Systems, C. E. Shannon (Bell System Technical Journal, vol. 28, no. 4, 1949)Confusion and diffusion as the two methods of frustrating statistical analysis, and the proof that the Vernam system, the one-time pad, gives perfect secrecy when the key is random and never repeats.
- Steganography, NIST CSRC glossary, NISTSteganography as communicating in a way that hides the existence of the communication.
- RFC 7465: Prohibiting RC4 Cipher Suites, IETFRC4 as a stream cipher.
- FIPS 197: Advanced Encryption Standard, NISTAES as a block cipher working on blocks of 128 bits.
- US1310719A: Secret Signaling System, Google Patents (United States Patent Office record)Gilbert Vernam's Secret Signaling System patent, granted on 22 July 1919.