In the rail fence cipher the letters are written in a zigzag across several rows, or rails, going down and up like a fence, and then read off rail by rail. WEAREDISCOVERED on three rails becomes WECRERDSOEEAIVD. The key is the number of rails, from 2 to 20; letters are not replaced, only reordered.
Everything runs in your browser — the text goes nowhere
The link will contain the text (up to 500 characters) and settings — share it with care.
02
Diagram
a zigzag on 3 rails
W···E···C···R··
·E·R·D·S·O·E·E·
··A···I···V···D
Shows the first line of the text, up to 60 characters.
03
How it works
The zigzag
down · up · down
Letters go onto the rails one by one, top to bottom and back, like the rails of a fence.
Reading
rail by rail
The ciphertext is the top rail's letters, then the second rail's and so on: WEAREDISCOVERED → WECRERDSOEEAIVD.
Decoding
letters per rail
Knowing the number of rails and the length, you can count the letters on each rail and walk the zigzag again.
04
Frequently asked questions
The letters of the text go onto the rails in a zigzag: the first on the top rail, the second on the next one and so on down to the bottom, then back up. When the text runs out, you write down all the letters of the top rail, then the second rail, and so on. The diagram on this page draws the zigzag for your text.
The textbook example is WE ARE DISCOVERED on three rails. The top rail gives WECR, the middle one ERDSOEE and the bottom one AIVD, together WECRERDSOEEAIVD. Paste it into the Decode tab with three rails and the original comes back. The Russian «ШИФРЗАБОР» on three rails becomes «ШЗРИРАОФБ».
You need the number of rails. From the length of the text the zigzag is rebuilt exactly: how many letters landed on each rail is worked out first, then the ciphertext letters are laid onto the rails and read along the zigzag. That is what the Decode tab does. If the number of rails is unknown, step through it with minus and plus.
Both ciphers move letters without replacing them. In the scytale the text is written in straight rows and read down the columns; in the rail fence it goes in a zigzag, so the top and bottom rails hold about half as many letters as the middle ones. The same text and number of rows give different ciphertexts. The scytale is on the next tab.
Because of the picture: letters written in a zigzag across the rails look like a fence of wooden rails. It is also called the zigzag cipher. It is a teaching transposition cipher, used in computer science lessons to show that letters can be moved instead of replaced, and a common step in puzzles and escape games.
No. The zigzag is built in your browser and the text stays on your device; it is not sent to a server or written into the page address. Only the Share button creates a link with the text and the number of rails, and the note beside it says what goes in. Site statistics know only that the tool was used.