Rail Fence Cipher Encoder & Decoder
Encode or decode text with the Rail Fence transposition cipher — write the message in a zigzag across a chosen number of rails and read it off row by row.
How to use
- Choose Encode or Decode.
- Set the number of rails (2 or more) — this is the key.
- Type or paste your message or ciphertext.
- Read the result and copy it. Decoding with the same rail count reverses encoding.
About this tool
ShowHide
The Rail Fence is a transposition cipher: the letters of a message are written diagonally down and back up across a fixed number of rails, then read off one row at a time. Nothing is substituted — every letter of the plaintext is still there, in a different order — so the key is simply how many rails you used, and decoding with the same number puts everything back.
That "nothing is substituted" is the property that gives a transposition cipher away instantly. Count the letters in the ciphertext and the frequencies match ordinary text: E is still the most common letter, the distribution still looks like the language it came from. A substitution cipher shifts that curve onto different symbols; a transposition leaves it exactly where it was. So the first thing an analyst learns from a rail-fence message is that it is a rail fence, or something like one, before trying a single key.
The key space is the other half of the problem, and it is tiny. The number of rails can only run from two up to just under the message length, so a hundred-character message has fewer than a hundred possible keys and every one of them can be tried and read in the time it takes to scroll. Two rails is the degenerate case: it simply separates the odd-numbered letters from the even-numbered ones. The zigzag also repeats with a period of twice the rail count minus two, which is what a solver looks for when the rail count is unknown.
None of that makes it useless, just not secret. It is a genuinely good puzzle cipher, it is where most people meet the idea that rearranging can hide meaning as well as replacing can, and it composes: applying a transposition after a substitution defeats the frequency analysis that would have broken either one alone, which is roughly the insight that classical cryptography spent a few centuries working out. Use it for a puzzle, a lesson or a game — not for anything you would mind a stranger reading.
Frequently asked questions
What do the rails do?
The rails are the horizontal lines the zigzag bounces between. More rails change the pattern and the ciphertext; the recipient must use the same number to decode. With 2 rails the message simply splits into odd and even positions.
Does it keep spaces and punctuation?
Yes — every character including spaces is transposed. For a more traditional look, remove spaces and use uppercase before encoding, but it is not required here.
Is the Rail Fence cipher secure?
No. It is a historical pen-and-paper cipher with very few possible keys (the rail count), so it is trivial to break by trying each one. Use it for puzzles and learning, not real security.
How is a transposition cipher broken?
By counting letters. Rearranging a message does not change which letters it contains, so the letter frequencies still match ordinary English — which immediately tells an analyst that the text was transposed rather than substituted. From there the rail count is a small number to try exhaustively, and the correct one announces itself as soon as readable words appear.
What is this good for, if not for secrecy?
For teaching the idea that a cipher can hide arrangement rather than identity, and for puzzles where the solver is meant to find the key by hand. Its real historical descendants matter more than it does: transposition became one half of the pairing — substitute, then transpose — that serious ciphers used for a century, because each step hides what the other leaves visible.
Related tools
Caesar / ROT13 / Vigenère / Atbash Cipher
Encrypt or decrypt text with four classic substitution ciphers — Caesar shift, ROT13, Vigenère keyword, Atbash mirror.
Text
Leetspeak (1337) Converter
Translate text into leetspeak and decode 1337 back to letters, in your browser.
Text
Character & Word Counter
Count characters, words, sentences, lines, and bytes in real time.
Text
Case Converter
Convert text between UPPER, lower, Title, camelCase, snake_case and more.
Text
Lorem Ipsum Generator
Generate placeholder text by paragraphs, sentences, or words.
Text
Text Diff Viewer
Compare two pieces of text and see line-by-line or word-by-word additions and removals.
Text