Unit 7
Keeping secrets
Encode and break a Caesar cipher, then see why modern encryption holds up even when everyone knows how it works.
Read
Secrets, keys and ciphers
Imagine passing a note in class. If the teacher grabs it, everyone can read it. What if you wrote it so that only your friend could understand it, even if the teacher caught it? That is the whole idea of encryption: scrambling a message so that only someone with the right secret can unscramble it.
People have done this for thousands of years. An old Indian text on the arts, the Kamasutra, lists secret writing among the skills worth learning, and Roman writers say Julius Caesar protected his letters by shifting every letter along the alphabet. Today the same idea guards your messages, your bank app and the padlock in your browser.
Words to know
- Plaintext: the original, readable message.
- Ciphertext: the scrambled message.
- Cipher: the method (the algorithm) for scrambling and unscrambling.
- Key: the secret detail that tells the cipher exactly how to scramble this time.
- Encrypt / decrypt: to turn plaintext into ciphertext and back.
The Caesar cipher
In a Caesar cipher the key is a number, the shift. To encrypt, move every letter forward by the shift. After Z, wrap round to A.
Example (encrypt). Encrypt MEET AT NOON with shift 5.
- M, E, E, T move five places: R, J, J, Y.
- A, T become F, Y.
- N, O, O, N become S, T, T, S.
Ciphertext: RJJY FY STTS. Spaces and punctuation stay as they are.
Example (wrap-around). Encrypt ZEBRA with shift 4. Z is the 26th letter; four places on wraps to D. E, B, R, A become I, F, V, E. The ciphertext is DIFVE.
To decrypt, shift backwards by the same amount. With key 3, the ciphertext WKH FDW becomes THE CAT.
Breaking a Caesar cipher
An attacker does not know your key. But a Caesar cipher has only 25 useful keys (shift 0 changes nothing, and shift 26 is the same as 0). So the attacker tries them all, which is called a brute-force attack. Shift the ciphertext by 1, 2, 3 and so on until real words appear. By hand it takes minutes; a computer needs a blink.
Example. Break KHOOR ZRUOG. Try shifting back by 1: JGNNQ YQTNF, nonsense. By 2: IFMMP XPSME, nonsense. By 3: HELLO WORLD. It reads, so the key was 3.
There is also a clever shortcut called frequency analysis. In English, E is the most common letter. If the most common letter in a long ciphertext is L, then perhaps E was shifted to L, which is a shift of 7. You test that one guess and read the message at once. Hindi, French and other languages have their own letter patterns, and the trick works for them too.
A bigger key is not always enough
A substitution cipher replaces each letter with a different letter in a random jumble, not a neat shift. The number of possible jumbles is , far too many to try one by one. Yet it was broken for centuries by frequency analysis: the most common cipher letter probably stands for E, and so on, and the patterns in whole words give the rest away.
Lesson: a huge number of keys is necessary for security, but it is not enough if the cipher leaks patterns in the message.
How modern encryption stays safe
Modern ciphers such as AES (used for Wi-Fi, messaging apps and phone storage) are designed so that no shortcut is known. The attacker's only option is brute force, so everything depends on the size of the key. AES-128 uses a 128-bit key, which gives
possible keys. Suppose a very fast computer tests a trillion () keys per second. One year has about seconds, so it tests about keys a year, and trying them all would take roughly
That is about a billion times the age of the universe. Every extra bit in the key doubles the work, so ten extra bits make the attack 1,024 times harder.
Security depends on the key staying secret
A rule from the 1800s, called Kerckhoffs's principle, says a cipher should stay secure even if the attacker knows exactly how it works, as long as the key stays secret. That is why AES is published openly for the whole world to test. If an expert can break it, we want to find out. Secret methods tend to hide weaknesses; secret keys are the real protection.
So the strongest cipher in the world fails if:
- the key is easy to guess (a short password or a birthday),
- the key is written on a sticky note, or shared with the wrong person,
- the key is reused where it should not be.
A last puzzle: how do two people who have never met agree on a key without anyone else learning it? Your browser's padlock solves this with public-key encryption: one key to lock that can be shared with everyone, and a different private key to unlock that never leaves its owner. You will meet the maths later; for now remember that the private key must stay private.
Common mistakes
- "Hiding how my cipher works makes it secure." Only a secret key does that.
- "More scrambling steps are always better." Two Caesar shifts in a row, 3 and then 5, are the same as one shift of 8. Combine ciphers carelessly and you gain nothing.
- "Enough keys means unbreakable." Not if patterns such as letter frequencies show through.
- "Wrap-around is optional." Forget it and Z has nowhere to go.
Try it: Pick a shift, encrypt a short message and give the ciphertext (not the shift) to a friend. Can they break it? How long did it take, and how many tries would a computer need?
Lab
The Caesar workshop
Slide the shift to see the cipher alphabet move. First encrypt a message yourself, then break two secret messages by finding their shifts.
Your goals
- Encrypt a message correctly with the shift you are given.
- Break two ciphertexts by finding the shift, and type the plaintext.
The interactive lab opens once you register. Register to do this.
Quick check
Keeping secrets check
Eight questions on Caesar ciphers and keys. Write ciphertext in capital letters if you like; capitals do not matter.
1.Encrypt CAT with a Caesar shift of 3.
Answer with a word or phrase
2.KHOOR was encrypted with a Caesar shift of 3. What is the plaintext?
Answer with a word or phrase
3.Encrypt XYZ with a Caesar shift of 4.
Answer with a word or phrase
4.How many different shifts (not counting the shift that changes nothing) must an attacker try to be sure of breaking any Caesar cipher?
Answer with a number
5.According to Kerckhoffs's principle, what should be the only secret in a good cipher system?
- The key
- The method the cipher uses
- Both the key and the method, to be doubly safe
- The length of the message
Choose one
6.Match each term to its meaning.
- Plaintext
- Ciphertext
- Key
- Cipher
Match each to: The scrambled message · The method for scrambling and unscrambling · The readable message · The secret that sets how to scramble
7.IFMMP is the Caesar encryption of HELLO. What shift was used?
Answer with a number
8.Which statements about modern encryption such as AES-128 are true?
- It has about 3.4 × 10^38 possible keys, far too many to try one by one
- Adding one bit to the key doubles the number of keys
- It stays safe only if the cipher's method is kept secret
- It can be broken in minutes by trying all keys on a laptop
Choose all that apply
Answering and checking are for registered learners. Register to do this.
Quick check
New puzzles with ciphers
Break a message and reason about keys in situations the reading did not show.
1.A Caesar-encrypted message reads ZLL FVB HA ZPE. The most common letter is L, and you guess it stands for E. Find the shift and give the plaintext.
Answer with a word or phrase
2.A computer tests 1,000,000 keys per second. A cipher has 2^40 keys (about 1.1 × 10^12). In the worst case, how many days does it take to try them all? (There are 86,400 seconds in a day.)
Answer with a number
3.The designers add 10 more bits to the key of the cipher above. By what factor does the worst-case time grow?
Answer with a number
4.Zara encrypts a message with a Caesar shift of 3, and then encrypts the result again with a shift of 5, hoping it is twice as secret. What single shift does the double encryption equal?
Answer with a number
5.A substitution cipher has about 4 × 10^26 keys, yet people broke it without trying every key. Why was that possible?
- Letter frequencies and word patterns still show through, so the attacker can guess the key piece by piece
- They were lucky
- It actually has only 25 keys
- The method had been kept secret and leaked
Choose one
Answering and checking are for registered learners. Register to do this.
Your turn
Break it, then defend it
- Encrypt the message
BE AT THE WELLwith a Caesar shift of 16, showing how you handled letters near the end of the alphabet. - A friend says: "My secret is safe, because only I know that I used a Caesar cipher." Explain, step by step, how an attacker who knows nothing about the shift could still read your ciphertext
RU QJ JXU MUBB. Say how many tries the attacker needs at most. - Explain why modern encryption such as AES is considered hard to break even though its method is public. Use the idea of the number of keys, and say what must stay secret.
How it's judged
- Encrypting correctly
- Breaking a Caesar cipher
- Why modern encryption holds up
Writing and submitting your answer is for registered learners. Register to do this.
- Encrypt the message
Like what you see?
Register for free to answer the quick checks, do the activities and save your work. Your work is saved on your device and syncs to your account.