Decrypting a Caesar cipher in Python
Decrypts by calling the same Caesar function with the negative of the original shift. Shifting back by the same amount undoes the encryption, and % keeps the letters wrapping.
Understanding Decrypting a Caesar cipher in Python in ACARA Digital Technologies Years 9–10
What it does: Encrypting with 3 and then calling the same function with -3 should give the original message back, so the comparison prints True. The decrypt shift is the negative of the encrypt shift, so a shift of 5 is undone with -5. The same function works both ways. Only the sign of the shift changes. The % operator only handles wrap-around. It adds no real security. Shifting A back by 1 wraps around to Z because % 26 keeps the position inside the alphabet. Going back by 3 lands on the same letter as going forward by 23, because 26 - 3 = 23.
Common mistakes: Calling caesar with the same shift encrypts the text a second time instead of undoing it. To decrypt, pass the negative shift: caesar(cipher, -shift). The value used for decrypting must be the negative of the original shift. It should be back = -shift, otherwise the text is shifted forward again.
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 860–875) 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
caesar(cipher, -shift)Fill in the Blanks
Spot the Error
Student with a class code? Join your class →