Breaking a Caesar cipher by trying every shift

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Breaking a Caesar cipher by trying every shift

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. How many different shifts could an attacker need to try to break a Caesar cipher?
A Millions
B 25
2. Which method breaks a Caesar cipher without knowing the key?
A Try every shift from 1 to 25 until the text is readable
B Guess one shift and give up if it fails
3. The attacker decrypts ciphertext with shift 7 and gets 'XQZ PLW BTR'. What should they do?
A Try the next shift, because the text is not readable
B Stop, because shift 7 must be the key
4. How does an attacker know they have found the right shift?
A The result turns into readable words
B The result turns into a longer message
5. Why is having only 25 possible keys a weakness?
A The message becomes too long to send
B An attacker can check every key quickly

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1for shift in range(1, 26): ABrute force means trying every shift, not guessing one. The real key could be any number from 1 to 25.
2if "THE" in guess: BLoops through every possible Caesar shift from 1 to 25 so each one can be tested
3A Caesar cipher has only 25 possible keys, so an attacker can test them all Ctotal_keys = 25
4Brute force means trying every shift and printing each result to look for readable text Dprint(shift, decrypt(text, shift))
5for shift in range(1, 25): Erange(1, 25) stops at 24, so shift 25 is never tested and the correct key could be missed.
6Only try shift 3, because that is the common one. FChecks whether a decrypted guess contains a real word, which suggests the shift was correct

Definitions

brute force

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
for shift in range(1, __): print(shift)
2.
___ shift in range(1, 26): print(shift)
3.
for shift in range(1, 26): print(shift, decrypt("KHOOR", _____))
4.
plain = decrypt(text, shift) if "the" __ plain: print("Found it!", shift)
5.
keys = list(range(1, 26)) print(___(keys))

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A text = "KHOOR"
B for k in range(1, 25):
C print(k, shift(text, -k))
Question 2
A text = "KHOOR"
B for k in range(1, 26):
C plain = decrypt(text, k)
D print(k, text)
Question 3
A shifts = list(range(1, 26))
B count = len(shifts) + 1
C print(count, "keys to try")
Question 4
A for k in range(1, 26):
B guess = decrypt(text, k)
C if "THE" in text:
D print("Found key", k)
Question 5
A total_keys = 26
B tried = 10
C left = total_keys - tried
D print(left, "shifts left")

Answer Key

Breaking a Caesar cipher by trying every shift
Section A: Quick Questions
Q1
B — 25
Q2
A — Try every shift from 1 to 25 until the text is readable
Q3
A — Try the next shift, because the text is not readable
Q4
A — The result turns into readable words
Q5
B — An attacker can check every key quickly
Section B: Match the Pairs
Q1
for shift in range(1, 26): → Loops through every possible Caesar shift from 1 to 25 so each one can be tested
Q2
if "THE" in guess: → Checks whether a decrypted guess contains a real word, which suggests the shift was correct
Q3
A Caesar cipher has only 25 possible keys, so an attacker can test them all → total_keys = 25
Q4
Brute force means trying every shift and printing each result to look for readable text → print(shift, decrypt(text, shift))
Q5
for shift in range(1, 25): → range(1, 25) stops at 24, so shift 25 is never tested and the correct key could be missed.
Q6
Only try shift 3, because that is the common one. → Brute force means trying every shift, not guessing one. The real key could be any number from 1 to 25.
Section C: Definitions
Q1
brute force — Trying every possible key, such as all 25 Caesar shifts, until readable text appears. A cipher with so few keys is weak because an attacker can check them all quickly.
Section D: Fill in the Blanks
Q1
for shift in range(1, 26): print(shift)
Q2
for shift in range(1, 26): print(shift)
Q3
for shift in range(1, 26): print(shift, decrypt("KHOOR", shift))
Q4
plain = decrypt(text, shift) if "the" in plain: print("Found it!", shift)
Q5
keys = list(range(1, 26)) print(len(keys))
Section E: Spot the Error
Q1
B — range(1, 25) stops at 24, so shift 25 is never tested. To try every Caesar key the loop must be range(1, 26).
Q2
D — This prints the original ciphertext every time, so the attacker never sees the decrypted attempt. It should print k and plain.
Q3
B — A Caesar cipher has only 25 keys, and len(shifts) is already 25. Adding 1 gives 26, which is wrong. It should be count = len(shifts).
Q4
C — This checks the original ciphertext, which never changes, so it can never spot readable text. It must check the decrypted guess: if "THE" in guess.
Q5
A — A Caesar cipher has 25 useful keys. A shift of 26 returns the original letters, so it is not a real key. It should be total_keys = 25.