How the rail fence cipher works
Pick a number of rails. Write the first letter on the top rail, the next on the rail below, and so on down. When you reach the bottom rail, turn and climb back up, one letter per step. With three rails, WE ARE DISCOVERED runs:
W . . . E . . . C . . . R . .
. E . R . D . S . O . E . E .
. . A . . . I . . . V . . . D
Now read each rail from left to right, one after another: WECR then ERDSOEE then AIVD. That is the ciphertext. The diagram under the tool draws the fence for whatever you type.
How to break it
The only secret is the number of rails, and it can’t sensibly be larger than the message. So try 2 rails, then 3, then 4, until words appear. That is all the breaker here does, scoring each attempt automatically.
A rail fence can be recognised by its statistics. The letter counts are exactly those of plain English, since no letter has been changed, yet the text is unreadable. The frequency analysis page will show you this at a glance.
Where it comes from
Transposition is as old as substitution; the Greeks were winding messages round rods (the scytale) in the fifth century BC. The rail fence proper was used as a field cipher in the American Civil War, where it had the great merit of needing nothing but a pencil. It was sometimes combined with a substitution cipher, so that breaking one layer left the analyst facing the other.
The name is American too: a rail fence is the zigzag split-timber fence of the old frontier.
Questions people ask
How do I decode a rail fence cipher?
Work out how many letters fall on each rail for the message length, cut the ciphertext into pieces of those sizes, lay each piece along its rail, then read along the zigzag. The tool does this as you type in the red pane.
How do I decode it if I don't know the number of rails?
Try them all. There are never more options than the message has letters, and usually only a handful are plausible. The break button tries every rail count and picks the result that reads as English.
Are spaces included in the zigzag?
On this page, yes. Every character you type takes a place on the fence, which means decoding returns your message exactly. Many puzzle setters remove spaces first; if a message came without spaces, it will decode without them.
How can I tell a transposition cipher from a substitution cipher?
Count the letters. A transposition only rearranges them, so E, T and A are still the most common, just as in normal English. In a substitution the common letters are unusual ones.