Breaking a Caesar cipher by trying every shift
Trying every possible key, such as all 25 Caesar shifts, then choosing the result that reads as sensible text. A short key leaves few shifts to try, so the cipher is weak.
Understanding Breaking a Caesar cipher by trying every shift in ACARA Digital Technologies Years 9–10
What it does: The loop covers all 25 keys, which is the whole key space of a Caesar cipher. Printing the shift beside each attempt lets the attacker see which one is readable and so find the key. A Caesar key is a shift from 1 to 25 (shift 0 or 26 changes nothing), so there are only 25 keys to try. A brute-force attack tries every key, then you pick the output that reads as sensible text. With so few keys, a computer (or even a person) can try them all in seconds. Gibberish means the shift is wrong, so move on to the next shift in the list.
Common mistakes: The loop prints the original ciphertext c every time, so the student never sees the 25 decrypted attempts. It should print p, the decrypted text, so they can spot the readable one. The arguments are the wrong way round. decrypt expects the ciphertext first and the shift second, so it should be decrypt(text, key).
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.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
brute-force attackFill in the Blanks
Spot the Error
Student with a class code? Join your class →