Slide 1 of 7 · Settling starter · Computer Science · Year 9
5 minutesCracking a Caesar cipher with letter frequencies
Clwb Codio Conwy is a code club for Year 9 pupils. Two members, Nia and Rhodri, have been sending each other messages scrambled with a Caesar cipher. Another member copied one of their long messages from the club noticeboard, and nobody told him the key. Today you find out whether a Caesar cipher kept the message safe.
While the register is called: write your name, class and date on your worksheet, then read sections 1 to 3 of the stimulus sheet, Clwb Codio Conwy: the intercepted message.
Starter question: Using the alphabet strip in section 3, Y is position 24. With key 3, what letter does Y become?
Slide 2 of 7 · Today’s brief and key words · Computer Science · Year 9
3 minutesYour brief: use a Caesar cipher, break it 2 ways, decide what needs encrypting
You will encrypt and decrypt with a Caesar cipher, break a message by brute force, break a long message by counting letters and comparing them with normal English, work out how long brute force takes a computer, and decide which kinds of data really need strong encryption before they are stored or shared.
Key
The secret that tells you how to encrypt and decrypt. In a Caesar cipher it is how many places each letter moves along the alphabet.
Ciphertext
The scrambled message. Plaintext is the readable message before it is scrambled.
Brute force
Trying every possible key until one works.
Frequency analysis
Counting how often each letter appears and comparing the counts with normal English.
Slide 3 of 7 · Steps 1 to 3: encrypt, decrypt, brute force · Computer Science · Year 9
13 minutesStep 1, Step 2 & Step 3: encrypt with key 5, decrypt with key 4, then brute force
Step 1 (6 min): encrypt LEAVE AT DAWN with key 5 using the alphabet strip; the first letter is done. Then show the MOD working for W. Step 2 (4 min): decrypt Rhodri’s message XLI OIC MW YRHIV XLI QEX by moving each letter back 4, and say why writing “key = 4” on the note makes it useless. Step 3 (6 min): nobody knows the key for Nia’s PHHW DW QRRQ. Try keys on the first word only, moving back, and stop at a real word.
| Key tried | PHHW becomes | Real word? |
|---|---|---|
| 1 | OGGV | No |
| 2 | NFFU | No |
Slide 4 of 7 · Step 4: frequency analysis · Computer Science · Year 9
20 minutesStep 4: count, work out percentages, draw, compare and decrypt
The long message in section 4 of the stimulus has a key nobody knows. Instead of trying every key, use data. (a) With your partner, one of you tallies lines 1 and 2, the other lines 3 and 4; then add your counts. (b) The total must be 184. (c) For your 5 most common letters, work out count ÷ 184 × 100 to 1 decimal place. (d) Bar chart, most common first, 1 square = 2%, both axes labelled. (e) Compare with the English chart in section 5: which letter stands for E, and how many places has it moved? (f) Test your key on your 2nd and 3rd letters and the most common word. (g) Decrypt line 1. (h) Why does your E percentage not match 12.7% exactly?
| Letter | Count | Working: count ÷ 184 × 100 | % |
|---|---|---|---|
| L | 33 | 33 ÷ 184 × 100 = 17.93… | 17.9 |
Slide 5 of 7 · Step 5: how long would brute force take? · Computer Science · Year 9
7 minutesStep 5: how long would brute force take a computer?
A computer can try about 1,000,000,000 (109) keys every second. There are about 31,500,000 seconds in a year. Divide the number of keys by 1,000,000,000 to get seconds, then give each time in a sensible unit: seconds, minutes or years.
| What is being guessed | Number of possible keys | Working | Longest time to try them all |
|---|---|---|---|
| Caesar cipher key | 25 | 25 ÷ 1,000,000,000 | 0.000000025 s: instant |
| 8 lower-case letters, such as ffrwdlan | 268 = 208,827,064,576 | ? | ? |
| 128-bit AES key | about 3.4 × 1038 | ? | ? |
Slide 6 of 7 · Step 6 and self check · Computer Science · Year 9
8 minutesStep 6: when should data be encrypted? Then check your work
(a) For each of the 5 situations, say whether the data should be encrypted when it is stored or sent, with a reason. (b) Write 3 to 5 sentences for a Year 7 pupil: what the padlock and https mean, why modern encryption is safe when a Caesar cipher is not, and 1 thing the padlock does not tell you. Use Steps 4 and 5 as evidence. Then tick the success criteria you have met and correct 1 thing.
- I can encrypt and decrypt a message with a Caesar cipher, including letters that wrap round from Z to A.
- I can explain why a key must be shared separately from the message, and why 25 keys is far too few.
- I can count letters accurately, check my total, and turn counts into percentages.
- I can compare my bar chart with a chart of normal English, use it to find the key and check it with more than 1 letter.
- I can decide when data should be encrypted before it is stored or shared, and explain what the https padlock does and does not tell me.
Slide 7 of 7 · Plenary review · Computer Science · Year 9
2 minutesQuick-check answers before handing in
Check your main answers before your worksheets are collected.
| Question | Correct answer |
|---|---|
| What is LEAVE AT DAWN with key 5? | QJFAJ FY IFBS |
| What key was used for the long message, and which letter gave it away? | Key 7. L was the most common letter (33 of 184), so it stood for E. |
| How long would a computer take to try every Caesar key, and every 128-bit AES key? | Caesar: instant (0.000000025 s). AES: about 1.1 × 1022 years. |