Caesar cipher wrap-around with MOD 26

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

Caesar cipher wrap-around with MOD 26

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A Caesar cipher uses shift 5. What does the letter X (position 23) become?
A 28
B C
2. Which formula wraps a shifted letter back around the alphabet (A=0 to Z=25)?
A (position + shift) MOD 26
B (position + shift) MOD 25
3. Shift 3: what does Y (position 24) become?
A B
B A
4. True or false: 26 MOD 26 = 0, so a letter shifted from position 20 by 6 lands on A.
A True
B False
5. Why do we need MOD 26 in a Caesar cipher?
A So the shift is always 26
B So letters past Z loop back to A

Match the Pairs

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

Left columnRight column
1(23 + 5) MOD 26 ADecrypts C with a shift of 5 by moving back 5 places, wrapping round to position 23, which is X
2(2 - 5 + 26) MOD 26 BnewPos = (pos - shift + 26) MOD 26
3To encrypt, add the shift to the letter's position, then use MOD 26 so the result stays between 0 and 25 CThe alphabet has 26 letters, so the wrap must use MOD 26, not MOD 25. With MOD 25, Z (25) would wrongly wrap to 0 and letters would be miscalculated.
4To decrypt with a negative shift, subtract the shift, add 26 so it is not negative, then wrap with MOD 26 DThere is no MOD 26, so X (23) shifted by 5 gives 28, which is not a letter. The result never wraps back to the start of the alphabet.
5newPos = (pos + shift) MOD 25 EnewPos = (pos + shift) MOD 26
6newPos = pos + shift FEncrypts X with a shift of 5: 28 wraps around to 2, which is the letter C

Definitions

(position + shift) MOD 26

Fill in the Blanks

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

1.
(23 + 5) ___ 26 = 2
2.
(23 + 5) MOD __ = 2
3.
newPos = (pos _ shift) MOD 26
4.
=MOD(2+__,26)
5.
X = 23 23 + 5 = 28 28 MOD 26 = _

Spot the Error

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

Question 1
A pos = ord('X') - 97
B shift = 5
C new = (pos + shift) % 26
D print(chr(new + 65))
Question 2
A pos = 25
B new = (pos + 3) % 25
C print(new)
Question 3
A shift = 5
B pos = (23 * shift) % 26
C letter = chr(pos + 65)
D print(letter)
Question 4
A pos = 2
B shift = -5
C new = (pos - shift) % 26
D print(chr(new + 65))
Question 5
A letter = 'C'
B pos = ord(letter) - 65
C shift = -5
D new = pos + shift % 26
E print(chr(new + 65))

Answer Key

Caesar cipher wrap-around with MOD 26
Section A: Quick Questions
Q1
B — C
Q2
A — (position + shift) MOD 26
Q3
A — B
Q4
A — True
Q5
B — So letters past Z loop back to A
Section B: Match the Pairs
Q1
(23 + 5) MOD 26 → Encrypts X with a shift of 5: 28 wraps around to 2, which is the letter C
Q2
(2 - 5 + 26) MOD 26 → Decrypts C with a shift of 5 by moving back 5 places, wrapping round to position 23, which is X
Q3
To encrypt, add the shift to the letter's position, then use MOD 26 so the result stays between 0 and 25 → newPos = (pos + shift) MOD 26
Q4
To decrypt with a negative shift, subtract the shift, add 26 so it is not negative, then wrap with MOD 26 → newPos = (pos - shift + 26) MOD 26
Q5
newPos = (pos + shift) MOD 25 → The alphabet has 26 letters, so the wrap must use MOD 26, not MOD 25. With MOD 25, Z (25) would wrongly wrap to 0 and letters would be miscalculated.
Q6
newPos = pos + shift → There is no MOD 26, so X (23) shifted by 5 gives 28, which is not a letter. The result never wraps back to the start of the alphabet.
Section C: Definitions
Q1
(position + shift) MOD 26 — Caesar wrap-around rule: with A=0 to Z=25, add the shift then take MOD 26 so letters past Z loop back to A. Example: X (23) + 5 = 28, MOD 26 = 2, which is C.
Section D: Fill in the Blanks
Q1
(23 + 5) MOD 26 = 2
Q2
(23 + 5) MOD 26 = 2
Q3
newPos = (pos + shift) MOD 26
Q4
=MOD(2+-5,26)
Q5
X = 23 23 + 5 = 28 28 MOD 26 = 2
Section E: Spot the Error
Q1
A — Capital letters start at ord 65, not 97 (that is for lowercase). Subtracting 97 gives a negative position. It should be ord('X') - 65 so that X = 23.
Q2
B — The alphabet has 26 letters, so the wrap-around uses MOD 26. MOD 25 gives the wrong result: Z (25) + 3 = 28, and 28 MOD 26 = 2 (C). It should be % 26.
Q3
B — A Caesar shift is added to the position, not multiplied. X (23) + 5 = 28, and 28 MOD 26 = 2 (C). It should be (23 + shift) % 26.
Q4
C — Decrypting uses a negative shift, so you add it: 2 + (-5) = -3, and -3 MOD 26 = 23 (X). Subtracting a negative shift adds 5 instead and gives the wrong letter. It should be (pos + shift) % 26.
Q5
D — MOD is worked out before the addition, so only shift is wrapped and the total can go outside 0-25. Brackets are needed: (pos + shift) % 26.