Rail Fence Cipher Encoder and Decoder
Encrypt and decrypt with the rail fence (zigzag) cipher using 2 to 10 rails. See the zigzag pattern and copy the result. Free, runs in your browser.
How it works
The rail fence cipher is a transposition cipher: it does not change any letter, it only changes their order. Write the message diagonally down and up across a number of rows, called rails, in a zigzag. Then read the first rail from left to right, then the second, and so on, and join them. To decrypt, mark the zigzag positions for a text of the same length, fill the rails in order with the ciphertext, and read along the zigzag. With the setting Letters and digits only, spaces and punctuation are removed first, as in most puzzles. With Keep spaces and punctuation, every character takes part, so the decrypted text keeps its spaces. The zigzag under the result shows where each character sits, with a dot for empty places and _ for a space.
Example: WE ARE DISCOVERED. RUN AT ONCE. on 3 rails becomes WECRUOERDSOEERNTNEAIVDAC.
The zigzag with 3 rails
WEAREDISCOVEREDRUNATONCE written across 3 rails (dots are empty places):
W...E...C...R...U...O... | .E.R.D.S.O.E.E.R.N.T.N.E | ..A...I...V...D...A...C.
The same message with 2, 3 and 4 rails
| Rails | Ciphertext |
|---|---|
| 2 | WAEICVRDUAOCERDSOEERNTNE |
| 3 | WECRUOERDSOEERNTNEAIVDAC |
| 4 | WIRAEDSEENTEAECVDUOCRORN |
Frequently asked questions
How do I decode a rail fence cipher?
Choose Decrypt, set the number of rails and paste the text. If you do not know the number of rails, try 2, 3, 4 and so on until the text reads correctly.
How many rails should I use?
Two or three rails are the most common in puzzles. More rails mix the text more, but the key still has only a few possible values, so it is easy to guess.
Should I keep spaces?
Puzzles usually remove spaces and punctuation before encrypting. Keep them only if the person decrypting will use the same setting, or the result will not match.
Why is it called rail fence?
The zigzag of letters across the rows looks like the rails of a split rail fence.
Is the rail fence cipher secure?
No. The letters are unchanged and the number of rails is small, so trying each one breaks it in seconds.
Is my text sent to a server?
No. Everything runs in your browser and the text you type is not sent anywhere.
More text tools
Cipher Decoder and Identifier
Morse Code Translator
Binary Translator
ASCII Converter
Hex to Text Converter
Leet Speak Translator
Caesar Cipher Encoder and Decoder
Vigenere Cipher Encoder and Decoder
Atbash Cipher Encoder and Decoder
Word Counter and Character Counter
ROT13 Decoder and Encoder
Playfair Cipher Encoder and Decoder
Braille Translator
Pigpen Cipher Translator
Letter to Number Converter (A1Z26)
Bacon Cipher Encoder and Decoder
Tap Code Translator
Polybius Square Cipher
The rail fence cipher is for puzzles and learning, not for real secrets.