Rail Fence Cipher Decoder
Decode a message written in the rail fence cipher right in your browser, or switch to any other classical cipher.
Input
Output
Guide
How do you decode the rail fence cipher?
A rail fence cipher text is the message read off rail by rail, so decoding puts its letters back on the zigzag. For that, you need the number of rails it was written with. Draw the zigzag with a dot for every letter, then fill the top rail's dots with the first letters of the cipher text, the next rail's dots with the letters after them, and so on. Reading along the zigzag, down and up, gives the message. BSTYAEAEOAKLD has 13 letters, so on 3 rails, the top rail takes 4 of them, the middle rail 6 and the bottom rail 3:
B . . . S . . . T . . . Y
. A . E . A . E . O . A .
. . K . . . L . . . D . .Along the zigzag, it reads BAKESALETODAY: bake sale today.
Tool description
Paste the scrambled text into the Cipher text box, or use the paste button under it, and set Rails to the number it was written with. The field starts at 3. As you type, the message forms in the Plain text box, each letter and digit back in its place and in its own case. Gaps, punctuation and line breaks are copied over from the cipher text unchanged: groups of five give groups of five, and a text without spaces stays without them. Insert sample loads Sot atn ey uth pran oe aeko at 3 rails, which reads See you at the park at noon. To answer, press the swap button, which turns the tool around to encode and takes the decoded text along, or open the Rail Fence Cipher Encoder. Other classical ciphers wait in the Cipher menu. Nothing leaves your browser.
Examples
| Cipher text | Rails | Plain text |
|---|---|---|
Fehra annrs be dtie |
2 | Fresh bread at nine |
Ira rccce mfeln heatu? |
3 | Ice cream after lunch? |
HIYABRAPYTDPH |
4 | HAPPYBIRTHDAY |
BUERR SNENO RIGSR TMONC OW |
4 | BRING SUNSC REENT OMORR OW |
Mburrfo etf fasiskanf |
6 | Muffins for breakfast |
Is it a rail fence cipher?
A rail fence message has the letters of ordinary words, only out of order, so common letters such as E, T and A turn up as often as usual. Its first letter is still the first letter of the message, and if the spaces were left in, every word is as long as before. The columnar transposition cipher looks much the same: if no number of rails works, try the Columnar Transposition Cipher Decoder.
How to find the number of rails
- Start at 2 and go up one step at a time, watching the Plain text box. The right number turns the letters into words.
- There's no need to go past the number of letters: from there on, nothing changes.
- The Cipher Identifier runs through the rail counts for you: when a count gives English, it shows the message decoded, together with that number of rails. A short message can decode too, though a longer one gives a surer answer.
Good to know
- Spaces in the cipher text don't change which letters come out, only where the gaps fall: with 3 rails,
Bsty aeae oaklddecodes toBake sale today, andBstyaeaeoakldtoBakesaletoday. If the gaps were lost, add the spaces to the result yourself. - Some other tools put the spaces on the zigzag too, and their messages won't decode here with any number of rails. Replace each space with a digit the message doesn't use, such as 0, decode, and then turn the 0s back into spaces.
- An empty Rails field, a number below 2 or a fraction shows the message "Use at least 2 rails."