Brute-forcing a Caesar cipher in Python
A loop that tries every Caesar shift from 1 to 25. Each pass decrypts the message and prints the shift beside the result, so you can spot the readable one.
Understanding Brute-forcing a Caesar cipher in Python in ACARA Digital Technologies Years 9–10
What it does: The loop calls decrypt with every shift and prints each result, so the readable message can be found. range() stops one before its end value, so range(1, 26) gives 1 to 25. range(1, 25) would miss shift 25. The right shift turns the ciphertext back into readable text. The other attempts look like nonsense. break ends the loop. continue only skips to the next shift, so the loop would keep going. A tiny key space means a computer can test every key in a fraction of a second.
Common mistakes: This prints the original scrambled message every time, so you never see the decrypted attempts. It should be print(shift, out) to show the shift beside each result. A for statement must end with a colon. It should be for shift in range(1, 26):.
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 876–944) and word search (Modules 860–944).
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
for shift in range(1, 26):Fill in the Blanks
Spot the Error
Student with a class code? Join your class →