Transposition cipher: rail fence
A cipher that keeps the same letters but changes their order, like writing a message in a zigzag across rails and then reading each rail in turn.
Understanding Transposition cipher: rail fence in ACARA Digital Technologies Years 9–10
What it does: Sorting both texts gives the same list of letters, which shows the ciphertext is just a reordering of the plaintext. No letters were swapped for different ones. A transposition cipher rearranges the letters. Swapping letters for other letters is called substitution, like the Caesar cipher. Zigzag the letters: H, L, O land on rail 1 and E, L on rail 2. Read rail 1 first, then rail 2, to get HLOEL. Transposition never changes the letters themselves. It only moves them around. Rail 1 gets A and C. Rail 2 gets T, A and K. Rail 3 gets T. Read the rails in order to get ACTAKT.
Common mistakes: In a two-rail fence the bottom rail holds the letters at positions 1, 3, 5 and so on. Starting at 2 repeats letters from the top rail and drops others. It should be text[1::2]. The message is text, so it needs quotes. Without them Python treats MEETATNOON as a variable name and raises an error. It should be text = 'MEETATNOON'.
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
transposition cipherFill in the Blanks
Spot the Error
Student with a class code? Join your class →