Frequency analysis of ciphertext

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

Frequency analysis of ciphertext

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. An attacker counts the letters in a Caesar cipher message. Which letter is most common in the ciphertext?
A The letter that probably stands for E
B The letter that always stands for Z
2. Which is the best description of frequency analysis?
A Changing every letter to the next letter in the alphabet
B Counting how often each letter appears in ciphertext
3. In English, which letter is usually the most common?
A E
B Q
4. The most common ciphertext letter in a Caesar message is H. What is a good first guess for the shift?
A E became H, so the shift is 3
B H became E, so the shift is 8
5. Which message is easier to crack with frequency analysis?
A A short message with only five letters
B A long message with hundreds of letters

Match the Pairs

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

Left columnRight column
1frequency analysis Ashift = X - E = 23 - 5 = 18
2most common ciphertext letter = E? Bcount(letter) for each letter A to Z
3An attacker counts the letters in a ciphertext to see which one appears most often CA good first guess is that the most common ciphertext letter stands for E, the most common English letter
4If X is the most common ciphertext letter and it stands for E, the Caesar shift can be worked out DCounting how often each letter appears in ciphertext to guess which letters stand for common plaintext letters
5Most common ciphertext letter = Z, so Z must be E EFrequency analysis needs enough text. A very short message does not have enough letters for the counts to match normal English, so the guess can be wrong.
6Short message: HI. Frequency analysis always works perfectly FThe attacker assumed the most common ciphertext letter is always Z. Frequency analysis only says the most common ciphertext letter probably stands for E, whatever that ciphertext letter is.

Definitions

frequency analysis

Fill in the Blanks

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

1.
for letter in __________: counts[letter] += 1
2.
top = ___(counts, key=counts.get)
3.
shift = ord(top) - ord("_")
4.
if len(ciphertext) _ 100: print("Frequency analysis works well")
5.
total = len(ciphertext) percent = count / _____ * 100

Spot the Error

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

Question 1
A counts ← empty table
B FOR each letter in ciphertext
C counts[letter] -= 1
Question 2
A ciphertext ← 'KHOOR'
B counts ← count letters
C top ← letter with min count
Question 3
A top ← 'X'
B common ← 'E'
C shift ← top + common
Question 4
A counts ← count letters
B top ← most common letter
C shift ← top - 'E'
D PRINT encrypt(text, shift)
Question 5
A IF message is long
B attack is harder
C ELSE attack is harder

Answer Key

Frequency analysis of ciphertext
Section A: Quick Questions
Q1
A — The letter that probably stands for E
Q2
B — Counting how often each letter appears in ciphertext
Q3
A — E
Q4
A — E became H, so the shift is 3
Q5
B — A long message with hundreds of letters
Section B: Match the Pairs
Q1
frequency analysis → Counting how often each letter appears in ciphertext to guess which letters stand for common plaintext letters
Q2
most common ciphertext letter = E? → A good first guess is that the most common ciphertext letter stands for E, the most common English letter
Q3
An attacker counts the letters in a ciphertext to see which one appears most often → count(letter) for each letter A to Z
Q4
If X is the most common ciphertext letter and it stands for E, the Caesar shift can be worked out → shift = X - E = 23 - 5 = 18
Q5
Most common ciphertext letter = Z, so Z must be E → The attacker assumed the most common ciphertext letter is always Z. Frequency analysis only says the most common ciphertext letter probably stands for E, whatever that ciphertext letter is.
Q6
Short message: HI. Frequency analysis always works perfectly → Frequency analysis needs enough text. A very short message does not have enough letters for the counts to match normal English, so the guess can be wrong.
Section C: Definitions
Q1
frequency analysis — Counting how often each letter appears in ciphertext. The most common letter probably stands for E, so an attacker can work out the key.
Section D: Fill in the Blanks
Q1
for letter in ciphertext: counts[letter] += 1
Q2
top = max(counts, key=counts.get)
Q3
shift = ord(top) - ord("E")
Q4
if len(ciphertext) > 100: print("Frequency analysis works well")
Q5
total = len(ciphertext) percent = count / total * 100
Section E: Spot the Error
Q1
C — Counting letter frequencies means adding 1 to a letter's count each time it appears. It should be += 1, not -= 1.
Q2
C — The attacker wants the most common ciphertext letter, because it probably stands for E. It should be max count, not min count.
Q3
C — The key is the distance from E to the top ciphertext letter, so you subtract. It should be top - common, not top + common.
Q4
D — After finding the key, the attacker decrypts the message to read it. It should be decrypt, not encrypt.
Q5
B — Longer messages give more letters to count, so the frequencies are closer to normal English and the attack is easier. It should be 'attack is easier'.