Rail Fence Cipher
Write letters in a zig-zag across rails, then read them row by row.
How it works
- Choose a number of rails (rows), such as 3. Remove spaces from the message to keep the structure clear.
- Write the message diagonally down and up across the rails, forming a zig-zag pattern as you move left to right.
- Once the zig-zag is filled, read the letters off row by row. Joining these rows together gives the ciphertext.
- To decrypt, you reconstruct the same zig-zag shape, mark where letters will go, and then fill them in row by row using the ciphertext.
- This cipher shows how changing the order of letters alone (without changing the letters themselves) can hide the original message.
What is it?
The Rail Fence Cipher (also called the zigzag cipher) is a form of transposition cipher. It derives its name from the way the plaintext is written downwards and diagonally on successive 'rails' of an imaginary fence, then moving up when the bottom rail is reached, and so on. Once the message is laid out, the ciphertext is read off in rows. It offers very little security as the number of practical keys (rails) is small, making it trivial to brute-force.
Try it yourself
Manual Solver & Visualizer
Can you decrypt this challenge?
How to draw the Rail Fence:
Write the message in a zig-zag pattern across the "rails" (rows), then read off each row from top to bottom.
| C | - | - | - | R | - | - | - | U | - | - | - | Y | - |
| - | Y | - | E | - | S | - | C | - | R | - | T | - | |
| - | - | B | - | - | - | E | - | - | - | I | - | - |
Example for "CYBERSECURITY" on 3 Rails.
Where this shows up today
To provide a rapid, pen-and-paper method to scramble messages in the field.