Using the rail fence tool
Type on the left and the reordered text appears on the right. Rails sets how deep the zigzag goes, from 2 to 10, and it's the whole key. Swap the boxes to read a message back.
Raise the rail count and the letters scatter further from where they started. Set it as high as the message is long and nothing moves at all, because every letter gets a rail to itself.
Why this one is different
Every other cipher on this site replaces letters. This one keeps them and changes the order. Write the text diagonally down and up across a set of rails, then read each rail left to right.
That distinction matters when you're trying to break it. A substitution cipher changes the letter frequencies, so counting letters tells you something. A transposition doesn't. The output of a rail fence has exactly the same letters as the input, in the same proportions, so a frequency count comes out looking like ordinary English.
It also means the cipher is easy to spot and easy to break. If a scrambled message has English letter frequencies, it's a transposition. There are only nine rail counts worth trying here, so the key space is smaller than the Caesar cipher's 25 shifts.
A cipher you can write in the dirt
The zigzag's one real virtue is that it needs no equipment. A soldier with a stick and a patch of dirt can run a rail fence, and the key is a single digit that fits in a memory under pressure.
Modern block ciphers still transpose. AES calls the step ShiftRows, and it moves bytes around the state in a fixed pattern. On its own that spreads nothing, just as a rail fence doesn't: change one letter of the plaintext and one letter of the output changes. AES alternates it with substitution and mixing for 10 to 14 rounds, and the combination spreads a single change across the whole block.
Related conversions
Caesar and Atbash are the substitution side of the family. Run one of them after a rail fence and you get something much harder to read than either alone, which is the idea Claude Shannon called a product cipher and the principle behind block ciphers like AES.
Text that looks like an anagram of English is usually a transposition, and the cipher identifier checks for that.
Questions
What is the rail fence cipher?
A transposition cipher. The message is written in a zigzag across a number of rails, then read off one rail at a time, so the letters are reordered rather than replaced.
How many rails should I use?
Three is the usual default and the one most puzzles expect. More rails scatter the letters further, but the key space stays tiny either way.
How do you break a rail fence cipher?
Try every rail count until the text reads. There are rarely more than about 10 worth testing, so it takes under a minute by hand.
Why do spaces and punctuation disappear?
They're stripped before the zigzag, because a space left in place would show word boundaries and give away the pattern. The letters are what the fence reorders.
Sources
- Wikipedia: Rail fence cipher
- Wikipedia: Advanced Encryption Standard
- Wikipedia: Product cipher
- NIST FIPS 197: Advanced Encryption Standard (ShiftRows; 10, 12 or 14 rounds)
Added . Last updated and reviewed . What's new



