Cipher
Runs in your browser. Your text never leaves your device.
Rail Fence Cipher Encoder and Decoder
Paste a rail fence ciphertext and this tool tries every rail count from 2 to 10 for you, putting the most readable result first, so you can read it without knowing the key. The rail fence cipher writes a message in a zigzag across a chosen number of rails, then reads each rail off in order to produce the ciphertext.
M aigbhll eetsietm tmdih yteodcoktwrna h ttoee nt co rean
Solved. Two independent checks agree on the top key.
- 3 railsfit readability 69 of 100, higher is better
Meet me at midnight by the old clock tower near the station
- 5 railsfit readability 31 of 100, higher is better
Mlh ch ey otteatet oosiiderecegto enkmb tta wthmr n ndlia
- 6 railsfit readability 30 of 100, higher is better
Mhmdtotc l ltoo ekm aedter wieithrnetn sgiya a tebteh nc o
Every rail count from 2 to 10, ranked by a readability heuristic (common English letter groups and words). Higher is better. Rail fence only reorders letters, so letter frequencies cannot tell the keys apart. Scores are a ranking aid, not a guarantee: read the text.
Solved. Best key: 3 rails, readability 69 of 100, higher is better.
Links carry your text after the # sign. Browsers never send that part of an address to a server, so it only reaches the people you share the link with.
Recent
Nothing yet. Your last 10 conversions, across every cipher, appear here. They are kept on this device only.
Rail Fence Cipher at a glance
- Type
- Broken cipher (keyed)
- Key space
- One key per rail count, typically under 30
- Directions
- Encode and decode: Plain text to Cipher text and back
- Example
HELLO→HOELL(3 rails, the tool's default)- Privacy
- Runs in your browser, nothing is uploaded
To encrypt, choose a rail count, type your message, and watch the scrambled text appear. Unlike Caesar or Vigenere it never changes a single letter, it only reorders them, which makes it a transposition cipher rather than a substitution one. Everything happens in your browser.
How the Rail Fence Cipher works
Write the message diagonally down and up across the chosen number of rails, like a bouncing ball: down to the bottom rail, back up to the top, and repeat. Each letter lands on exactly one rail.
To read the ciphertext, take the rails one at a time, top to bottom, and read each rail left to right. Decoding reverses this: the same zigzag pattern shows which position in the ciphertext belongs to which rail.
Examples
History and origins
Zigzag transposition is one of the oldest and simplest ways to disguise a message, used since antiquity for dispatches where speed mattered more than strength. It takes its name from the wooden zigzag rail fences once common on farms, which the diagonal writing pattern resembles.
It offers very little real protection. With a short message an attacker can simply try every reasonable rail count and read off the one that produces sensible words, which is why it is taught today mainly to introduce the idea of transposition.
Frequently asked questions
How do I decode a rail fence cipher?
You need the same number of rails used to encrypt. Rebuild the zigzag pattern for that length and rail count, then read the letters back off in zigzag order, which is exactly what this tool does when you swap direction.
Does the rail fence cipher keep spaces and punctuation?
This tool transposes every character you type, including spaces and punctuation, so decoding restores the exact original text, not just the letters.
How many rails should I use?
Two rails barely scrambles anything, since it is close to alternating letters. More rails scramble the order further, though with a short message it is still easy to guess the rail count by trial and error.
Learn more
Go deeper on the ideas behind this tool.
Not sure this is the right tool?
If you have a message and you are not certain what it is, the cipher identifier reads the character set and the letter statistics and tells you which scheme it most likely uses, and why. It covers every code and cipher on this site.