← QCE Digital Solutions Unit 4

Gronsfeld cipher

A Vigenere variant whose key is a string of digits 0-9, like 31415. Each digit is the shift for one letter, and the key repeats along the message.

Understanding Gronsfeld cipher in QCE Digital Solutions Unit 4

What it does: Adding the digit shifts the letter forward, and % 26 wraps past Z back to A. Subtracting the same digit reverses the encryption, and % 26 keeps the result between 0 and 25. A Gronsfeld key is a string of digits 0 to 9. A key made of letters like PIZZA belongs to the Vigenere cipher. Each digit is the shift for ONE letter. The first digit is 3, so A moves 3 places to D. Gronsfeld is a Vigenere variant with a numeric key. Both repeat the key along the message. MOD by the key length sends the position back to the start of the key, so 31415 repeats as 3,1,4,1,5,3,1,4...

Common mistakes: A Gronsfeld key is made only of digits 0-9, because each digit is a shift. Letters like ABCDE make a Vigenere key. It should be key = "31415". The key must repeat along the message. Using key[i] runs off the end of a short key. It should use i % len(key) to wrap back to the first digit.

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 17–88) and word search (Modules 17–125).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which one is a valid Gronsfeld cipher key?
31415PIZZA
Matches
key = '3A415'
↓
A Gronsfeld key can only use digits 0-9. The letter A makes this a Vigenere-style key and gives no valid numeric shift.
Applying
Meanings
Term
Gronsfeld cipher
Meaning
A Vigenere variant whose key is a string of digits 0-9, like 31415. Each digit is the shift for one letter, and the key repeats along the message.
Practice
key = "31415"
Testing
Gaps
shift = int(key[ % len(key)])
Check Answer
Spots
1key = "ABCDE"
2text = "HELLO"

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

The 'Moon Jellyfish' badge — Orbital Streak, 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. Which one is a valid Gronsfeld cipher key?
A. 31415 ✓
B. PIZZA
A Gronsfeld key is a string of digits 0 to 9. A key made of letters like PIZZA belongs to the Vigenere cipher.
2. The key is 31415 and the first message letter is A. What happens to it?
A. It shifts 31 places and becomes F
B. It shifts 3 places and becomes D ✓
Each digit is the shift for ONE letter. The first digit is 3, so A moves 3 places to D.
3. The key is 123 and the message has 7 letters. Which shifts are used?
A. 1 2 3 1 2 3 1 ✓
B. 1 2 3 0 0 0 0
The key repeats along the message until every letter has a shift digit.
4. How many different shifts can one Gronsfeld key digit give?
A. 26 (letters A to Z)
B. 10 (digits 0 to 9) ✓
A digit can only be 0 to 9, so there are only ten possible shifts per letter. A Vigenere key letter allows 26.
5. Key digit 2 was used to encrypt a letter and the cipher letter is F. What was the original letter?
A. D ✓
B. H
To decrypt, shift backwards by the digit. F moved back 2 places is D.

Match the Pairs

key = '31415' → A Gronsfeld key: a string of digits 0-9 where each digit is the shift for one letter
key[i % len(key)] → Picks the key digit for position i, repeating the key along a longer message
To encrypt, shift the letter number forward by its key digit and wrap round with MOD 26 → (n + shift) % 26
To decrypt, shift the letter number backward by the same key digit and wrap with MOD 26 → (n - shift) % 26
key = '3A415' → A Gronsfeld key can only use digits 0-9. The letter A makes this a Vigenere-style key and gives no valid numeric shift.
HI with key 31 gives KK → The same digit 3 was used for both letters. The key moves to the next digit, so I is shifted by 1 and becomes J. The correct result is KJ.

Key Term

Gronsfeld cipher
A Vigenere variant whose key is a string of digits 0-9, like 31415. Each digit is the shift for one letter, and the key repeats along the message.

Fill in the Blanks

1. shift = int(key[i % len(key)])
Hint: Type the variable that tracks the position of the current letter in the message.
2. shift = int(key[i % len(key)])
Hint: Type the operator that wraps the position back to the start so the key repeats.
3. new = (ord(ch) - 65 + shift) % 26 + 65
Hint: Type the operator that moves the letter forward by the digit when encrypting.
4. new = (ord(ch) - 65 - shift) % 26 + 65
Hint: Type the operator that moves the letter back by the digit when decrypting.
5. shifts = list(range(0, 10))
Hint: Type the stop value so range covers every possible key digit from 0 to 9.

Spot the Error

Question 1
A key = "ABCDE"
B text = "HELLO"
C d = int(key[0])
D print(d)
Line A — A Gronsfeld key is made only of digits 0-9, because each digit is a shift. Letters like ABCDE make a Vigenere key. It should be key = "31415".
Question 2
A key = "2718"
B text = "CATS"
C for i in range(len(text)):
D d = int(key[i])
E print(d)
Line D — The key must repeat along the message. Using key[i] runs off the end of a short key. It should use i % len(key) to wrap back to the first digit.
Question 3
A key = "31415"
B pos = 0
C d = int(key[pos])
D new = (7 + d) % 10
E print(new)
Line D — Letter positions wrap around the 26-letter alphabet, so the MOD must be 26. The digits 0-9 are the shifts, not the alphabet size. It should be % 26.
Question 4
A plain = (cipher + d) % 26
B letter = chr(plain + 65)
C print(letter)
Line A — Encrypting adds the digit shift, so decrypting must subtract it. It should be plain = (cipher - d) % 26.
Question 5
A key = "31415"
B d = key[0]
C shifted = (4 + d) % 26
D print(shifted)
Line B — key[0] is the text character "3", not a number, so it cannot be added to a letter position. It must be converted with int(), giving d = int(key[0]).

Student with a class code? Join your class →