← ACARA Digital Technologies Years 9–10

Caesar cipher wrap-around with 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.

Understanding Caesar cipher wrap-around with MOD 26 in ACARA Digital Technologies Years 9–10

What it does: Adding the shift can go past 25 (Z). MOD 26 wraps the number back into the range 0 to 25, so Z loops round to A. 23 + 5 = 28, which is past Z (25). 28 MOD 26 = 2, and position 2 is C. The alphabet has 26 letters, so we use MOD 26. The remainder is always between 0 and 25, which matches the positions A to Z. 24 + 3 = 27. 27 MOD 26 = 1, and position 1 is B. 20 + 6 = 26. 26 MOD 26 = 0, which is A. The alphabet has looped all the way round.

Common mistakes: 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. 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.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 828–859) and word search (Modules 810–859).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
A Caesar cipher uses shift 5. What does the letter X (position 23) become?
C28
Matches
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.
Applying
Meanings
Term
(position + shift) MOD 26
Meaning
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.
Practice
position = ord("X") - 65
Testing
Gaps
(23 + 5) 26 = 2
Check Answer
Spots
1pos = ord('X') - 97
2shift = 5

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Giant Isopod' badge — Patient Builder, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. A Caesar cipher uses shift 5. What does the letter X (position 23) become?
A. 28
B. C ✓
23 + 5 = 28, which is past Z (25). 28 MOD 26 = 2, and position 2 is 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
The alphabet has 26 letters, so we use MOD 26. The remainder is always between 0 and 25, which matches the positions A to Z.
3. Shift 3: what does Y (position 24) become?
A. B ✓
B. A
24 + 3 = 27. 27 MOD 26 = 1, and position 1 is B.
4. True or false: 26 MOD 26 = 0, so a letter shifted from position 20 by 6 lands on A.
A. True ✓
B. False
20 + 6 = 26. 26 MOD 26 = 0, which is A. The alphabet has looped all the way round.
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 ✓
Without MOD 26, a result like 28 would not match any letter. MOD 26 wraps the number back into the range 0 to 25.

Match the Pairs

(23 + 5) MOD 26 → Encrypts X with a shift of 5: 28 wraps around to 2, which is the letter C
(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
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
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
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.
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.

Key Term

(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.

Fill in the Blanks

1. (23 + 5) MOD 26 = 2
Hint: Type the operator that gives the remainder, so the total loops back into the range 0 to 25.
2. (23 + 5) MOD 26 = 2
Hint: Type the number of letters in the alphabet, which the total is wrapped around.
3. newPos = (pos + shift) MOD 26
Hint: Type the operator that moves a letter forward when you encrypt.
4. =MOD(2+-5,26)
Hint: Type the negative shift that undoes an encryption shift of five. C (2) should go back to X.
5. X = 23 23 + 5 = 28 28 MOD 26 = 2
Hint: Type the wrapped position after the MOD step. It is the position of the letter C.

Spot the Error

Question 1
A pos = ord('X') - 97
B shift = 5
C new = (pos + shift) % 26
D print(chr(new + 65))
Line 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.
Question 2
A pos = 25
B new = (pos + 3) % 25
C print(new)
Line 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.
Question 3
A shift = 5
B pos = (23 * shift) % 26
C letter = chr(pos + 65)
D print(letter)
Line 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.
Question 4
A pos = 2
B shift = -5
C new = (pos - shift) % 26
D print(chr(new + 65))
Line 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.
Question 5
A letter = 'C'
B pos = ord(letter) - 65
C shift = -5
D new = pos + shift % 26
E print(chr(new + 65))
Line 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.

Student with a class code? Join your class →