One-time pad cipher
A cipher that encrypts each letter with a random key letter. The key is as long as the message and is used once only, so it is unbreakable if used correctly.
Understanding One-time pad cipher in QCE Digital Solutions Unit 4
What it does: The key letter at position i gives the shift for the message letter at position i, so every letter has its own key letter. Making a fresh random key for every new message follows the use-once-only rule of a one-time pad. A truly random key leaves no pattern for an attacker to find. Words and names create patterns that can be guessed. The key length must match the message length. Using one letter for the whole message is just a Caesar cipher, which is easy to break.
Common mistakes: The key is built up as a string of random letters, so it must start as an empty string (key = ""). Starting at 0 would cause a type error when a letter is added. A one-time pad key must be as long as the message. The warning should show when the lengths are NOT equal, so the test should be len(key) != len(msg).
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 334–401) and word search (Modules 127–401).
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
one-time padFill in the Blanks
Spot the Error
Student with a class code? Join your class →