Decrypting a message with a Caesar shift

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

Decrypting a message with a Caesar shift

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A message was encrypted with a Caesar shift of 3. To decrypt it, which way do you move each letter?
A Forward 3 places along the alphabet
B Back 3 places along the alphabet
2. The key is 1. What is the plaintext letter for the ciphertext letter C?
A B
B D
3. The key is 1. What is the plaintext letter for the ciphertext letter A?
A Z
B B
4. Decrypt KHOOR with a key of 3. Which plaintext is correct?
A NKRRU
B HELLO
5. The key is 5. What is the plaintext letter for the ciphertext letter D?
A Y
B I

Match the Pairs

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

Left columnRight column
1K shifted back 3 = H Aplain = (cipher - key) mod 26
2B shifted back 3 = Y BKHOOR with key 5 = FCJJM (nonsense)
3To decrypt, subtract the key from each letter's position and wrap around the 26 letters CWrapping from A back to Z: B goes back to A, then Z, then Y.
4Check that the result is a real message, because a wrong key gives nonsense DDecrypting: move the ciphertext letter K three places back along the alphabet to get the plaintext letter H.
5KHOOR with key 3 -> NKRRU EThe shift did not wrap around. Going back 1 from A wraps to Z.
6A shifted back 1 -> no letter, stop FThe letters were moved forward by 3, which is how you encrypt. To decrypt, move each letter back by 3 to get HELLO.

Definitions

shift back by key

Fill in the Blanks

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

1.
plainNum ← cipherNum - ___
2.
plainNum ← (cipherNum - key) ___ 26
3.
FOR EACH letter IN __________ pos ← position(letter) - key
4.
IF plaintext is a real message THEN OUTPUT plaintext ____ try another key
5.
num = ord(letter) - 65 plain = (num - key) % __

Spot the Error

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

Question 1
A direction = 'forward'
B key = 3
C cipher = 'KHOOR'
D print(decrypt(cipher, key))
Question 2
A def decrypt_letter(c, key):
B n = ord(c) - 65
C n = (n + key) % 26
D return chr(n + 65)
Question 3
A n = (0 - 3) % 25
B print(n)
C print(chr(n + 65))
Question 4
A cipher = 'KHOOR'
B key = 3
C plain = ''
D for c in plain:
E n = (ord(c)-65-key) % 26
F plain += chr(n + 65)
Question 5
A plain = decrypt(cipher, key)
B if plain == cipher:
C print('Key found')
D else:
E print('Try another key')

Answer Key

Decrypting a message with a Caesar shift
Section A: Quick Questions
Q1
B — Back 3 places along the alphabet
Q2
A — B
Q3
A — Z
Q4
B — HELLO
Q5
A — Y
Section B: Match the Pairs
Q1
K shifted back 3 = H → Decrypting: move the ciphertext letter K three places back along the alphabet to get the plaintext letter H.
Q2
B shifted back 3 = Y → Wrapping from A back to Z: B goes back to A, then Z, then Y.
Q3
To decrypt, subtract the key from each letter's position and wrap around the 26 letters → plain = (cipher - key) mod 26
Q4
Check that the result is a real message, because a wrong key gives nonsense → KHOOR with key 5 = FCJJM (nonsense)
Q5
KHOOR with key 3 -> NKRRU → The letters were moved forward by 3, which is how you encrypt. To decrypt, move each letter back by 3 to get HELLO.
Q6
A shifted back 1 -> no letter, stop → The shift did not wrap around. Going back 1 from A wraps to Z.
Section C: Definitions
Q1
shift back by key — To decrypt a Caesar ciphertext, move each letter back along the alphabet by the key number to get the plaintext. A wraps back to Z. Then check the result is a real message.
Section D: Fill in the Blanks
Q1
plainNum ← cipherNum - key
Q2
plainNum ← (cipherNum - key) MOD 26
Q3
FOR EACH letter IN ciphertext pos ← position(letter) - key
Q4
IF plaintext is a real message THEN OUTPUT plaintext ELSE try another key
Q5
num = ord(letter) - 65 plain = (num - key) % 26
Section E: Spot the Error
Q1
A — Decrypting a Caesar cipher moves each letter BACK along the alphabet by the key. Moving forward is what encryption does. It should be direction = 'back'.
Q2
C — This adds the key, which moves the letter forward and re-encrypts it. To decrypt you subtract the key: n = (n - key) % 26.
Q3
A — The alphabet has 26 letters, so wrapping must use % 26. With % 26, shifting A back 3 gives 23, which is X. Using 25 gives the wrong letter.
Q4
D — The loop must go through each letter of the ciphertext. plain is empty at this point, so nothing would be decrypted. It should be for c in cipher:.
Q5
B — After decrypting you must check that the result is a real message that makes sense. Comparing it with the ciphertext does not test that. It should be if plain makes sense:.