Rail Fence Cipher
Beta: this tool hasn't been fully reviewed yet. Double-check results before relying on them.
Inputs
The key: both sides need the same number.
Results
The zigzag
Your input is too long to share as a link, so the page address no longer includes it.
The rail fence cipher writes the message diagonally down and up across several lines (the rails), like a zigzag fence, then reads each rail from left to right. Letters keep their identity but change places, so it’s a transposition cipher, a nice partner to letter-swapping ciphers like Caesar in puzzles and classrooms.
How to use it
- Choose Encode or Decode.
- Type the text and the number of rails. Spaces are removed unless you keep them.
- Copy the result. The zigzag shows where every letter goes.
Example: “WE ARE DISCOVERED FLEE AT ONCE” on 3 rails encodes to WECRLTEERDSOEEFEAOCAIVDEN. Decode it with 3 rails to get the message back.
Questions and answers
Is the rail fence cipher secure?
No. There are only a handful of sensible rail counts, so trying them all takes seconds. It’s for puzzles and learning.
How is it different from the scytale?
Both rearrange letters. The scytale writes rows and reads columns; the rail fence writes a zigzag and reads rows, so letters near each other end up spread unevenly.
Does capitalization matter?
No. Every character keeps its case and is simply moved; only the order changes.
Link with pre-filled values
Add # and these parameters to the end of this page's address to open the tool with values already filled in.
| Parameter | What it sets |
|---|---|
text | The message, or the cipher text to decode. |
rails | Number of rails (the key), 2 to 20. |
mode | encode or decode. |
spaces | true to keep spaces; false removes them first. |
Example: https://toolabelle.com/rail-fence-cipher/#text=Meet+me+at+the+park&rails=3&mode=encode&spaces=false