Wrapping around from Z to A

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

Wrapping around from Z to A

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A Caesar cipher uses a shift of 3. What does the letter X become?
A A
B D
2. The letters are numbered 0 to 25. Which number is Z?
A 25
B 26
3. Which describes the alphabet in a Caesar cipher shift?
A A straight line that stops at Z
B A circle of 26 letters
4. Shift Y by 3. What letter do you get?
A B
B C
5. X is number 23. Shifting by 3 gives 26, which is past the end of 0 to 25. What happens next?
A It stays as 26 and becomes a new letter
B It wraps around to 0, which is A

Match the Pairs

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

Left columnRight column
1(23 + 3) mod 26 = 0 A25 + 1 = 26, then 26 - 26 = 0
2(25 + 2) mod 26 = 1 BZ is number 25. Shifting it by 2 wraps around to 1, which is the letter B.
3The alphabet is a circle of 26 letters numbered 0 to 25, so the number after 25 goes back to 0 CX is number 23. Shifting it by 3 reaches 26, which wraps back to 0, the letter A.
4To count past Z, subtract 26 whenever the total is bigger than 25 Dif total > 25: total = total - 26
5X (23) shifted by 3 = 26, so the letter is 26 EThere is no letter 26. The numbers only go from 0 to 25, so 26 must wrap around to 0, which is A.
6Z (25) + 2 = 27, then 27 - 26 = 2, so the letter is C FThe sum is wrong. 27 - 26 is 1, not 2, and letter 1 is B, so Z shifted by 2 is B.

Definitions

wrap around

Fill in the Blanks

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

1.
newPos ← (pos + shift) ___ 26
2.
newPos ← (pos + shift) MOD __
3.
A ← 0 Z ← __
4.
IF pos _ 25 THEN pos ← pos - 26 END IF
5.
(__ + 3) MOD 26 gives 0, which is A

Spot the Error

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

Question 1
A letters = 25
B x = 23
C shift = 3
D new = (x + shift) % letters
Question 2
A num = 23
B shift = 3
C new = (num + shift) % 25
D print(new)
Question 3
A # A=0, B=1, ... Z=25
B num = ord(ch) - 65
C new = (num + 3) / 26
D print(chr(new + 65))
Question 4
A num = 25
B shift = 1
C total = num + shift
D new = total // 26
Question 5
A # A=1, B=2, C=3 ... Z=26
B z = 25
C new = (z + 1) % 26
D print(new) # 0 is A

Answer Key

Wrapping around from Z to A
Section A: Quick Questions
Q1
A — A
Q2
A — 25
Q3
B — A circle of 26 letters
Q4
A — B
Q5
B — It wraps around to 0, which is A
Section B: Match the Pairs
Q1
(23 + 3) mod 26 = 0 → X is number 23. Shifting it by 3 reaches 26, which wraps back to 0, the letter A.
Q2
(25 + 2) mod 26 = 1 → Z is number 25. Shifting it by 2 wraps around to 1, which is the letter B.
Q3
The alphabet is a circle of 26 letters numbered 0 to 25, so the number after 25 goes back to 0 → 25 + 1 = 26, then 26 - 26 = 0
Q4
To count past Z, subtract 26 whenever the total is bigger than 25 → if total > 25: total = total - 26
Q5
X (23) shifted by 3 = 26, so the letter is 26 → There is no letter 26. The numbers only go from 0 to 25, so 26 must wrap around to 0, which is A.
Q6
Z (25) + 2 = 27, then 27 - 26 = 2, so the letter is C → The sum is wrong. 27 - 26 is 1, not 2, and letter 1 is B, so Z shifted by 2 is B.
Section C: Definitions
Q1
wrap around — When a shift goes past Z, the count carries on from A, so X shifted by 3 becomes A. The alphabet works like a circle of 26 letters, numbered 0 to 25.
Section D: Fill in the Blanks
Q1
newPos ← (pos + shift) MOD 26
Q2
newPos ← (pos + shift) MOD 26
Q3
A ← 0 Z ← 25
Q4
IF pos > 25 THEN pos ← pos - 26 END IF
Q5
(23 + 3) MOD 26 gives 0, which is A
Section E: Spot the Error
Q1
A — The alphabet has 26 letters, numbered 0 to 25, so the wrap-around size must be 26, not 25. With 25, X shifted by 3 would not come out as A.
Q2
C — The remainder must use 26 because the circular alphabet has 26 letters. The line should be new = (num + shift) % 26, which gives 0 (A) for X shifted by 3.
Q3
C — Wrapping needs the remainder operator %, not division. Division gives a fraction and never carries the count on from A. It should be new = (num + 3) % 26.
Q4
D — // gives how many times 26 fits, which is 1 here, not the wrapped position. Use % to get the remainder: 26 % 26 = 0, which is A.
Q5
A — The letters are numbered 0 to 25, so A is 0 and Z is 25. The rest of the program uses 25 for Z and 0 for A.