Rail Fence Cipher
Rail fence cipher rearranges text along a zigzag path and reads it rail by rail; use the same rail count to decode it back. This page preserves characters and whitespace and does not guess the rail count or crack messages.
Ready. Start at the top rail, moving downward, with no offset.
View the plaintext zigzag path
Run a conversion to view its path.
Original path and recovery checks
We computed four text sequences with Python and this page’s independently written JavaScript. Both implementations agreed on each zigzag path and ciphertext. Each implementation then reconstructed the original from its ciphertext with the same rail count. Character counts were measured as Unicode code points, not UTF-8 bytes or JavaScript string units. All comparisons matched.
| Rails | Original text | Computed ciphertext | Decoded text | Unicode characters |
|---|---|---|---|---|
| 3 | WEAREDISCOVEREDFLEEATONCE | WECRLTEERDSOEEFEAOCAIVDEN | WEAREDISCOVEREDFLEEATONCE | 25 |
| 2 | ABCDE | ACEBD | ABCDE | 5 |
| 3 | Hi 🚀!\nGo | H!i🚀\no G | Hi 🚀!\nGo | 8 |
| 4 | Meet at 5 | Mtea e 5t | Meet at 5 | 9 |
In the five-letter sample, two rails produce the path 0, 1, 0, 1, 0. The first rail contains A, C and E; the second contains B and D. Reading the first rail followed by the second gives ACEBD. For recovery, the path tells us to consume three characters for the first rail and two for the second. Following the same path through those two segments returns ABCDE. This sample separates position rearrangement from alphabet substitution: the letters themselves do not change.
The eight-character mixed sample includes one emoji, a space and a real newline. Both calculations treated the emoji as one character and retained the whitespace instead of trimming it. The table displays a newline as \n; that display notation is not stored in the result. The final sample deliberately includes spaces and a digit, so its recovered text is compared with the exact original, not an uppercase or whitespace-normalized form.
We additionally tested every rail count from 2 through 50 with short text and Unicode input, including more rails than characters. Each round trip recovered its input. To reproduce a table row, enter its original text and rail count, encrypt, then press Reverse result. The tool keeps the same rail count while changing direction.
Input, output and limits
Paste one text input, up to 10,000 Unicode code points. Choose an integer rail count from 2 to 50. Text, digits, punctuation, case, spaces, line breaks and emoji are preserved; no trimming or normalization is applied. One code point is not always a complete visual character: combining marks are counted separately.
Output is text with one-click copy. This implementation starts on the top rail, moving down, and uses no offset. Decryption requires the supplied rail count and the same convention. No automatic rail search, cipher detection or cracking is provided. One input per run; no login, registration, file upload, batch mode, saved history or daily counter. Processing stays in your browser.
Does rail fence change letters or their positions?
It changes positions. The ABCDE row above becomes ACEBD, then recovers ABCDE with the same two-rail path. It does not use a replacement alphabet.
Does this keep a message secret?
No. This historical transposition is for learning and puzzles, not protection of confidential information. Having the rail count and the convention lets the recipient reverse it; this tool does not determine them from an unknown message.
Related classic tools
Caesar and ROT13, Atbash, Vigenere, Pigpen, Substitution Cipher, Bacon Cipher and Playfair use different letter or symbol transformations. Cipher Decoder displays alternatives without identification.
Related representation walkthrough
This walkthrough shows the measured two-rail example and how using the same rail count restores the characters.
Loading the player connects to YouTube and shares connection information such as your IP address and playback requests.
For candidate families based on stated features rather than decoded results, use the Cipher feature candidate tool.