This tool encrypts and decrypts rail fence text live as you type and never leaves your device. Set the number of rails - that is the whole key - and watch the fence preview show exactly how your text zigzags across the rows. Because it only reorders characters, it works on any text: spaces, punctuation, accents and emoji all survive a round trip, and decrypting with the same rail count returns your original message character for character.
Rail Fence Cipher
Runs entirely in your browser - no upload, no sign-up.
What is the rail fence cipher?
The rail fence cipher is a classic transposition cipher that writes a message in a zigzag down and up across a set number of rows, or rails, then reads it off row by row to scramble the letters. It hides nothing but the order of the characters, so decrypting is just reversing the zigzag with the same rail count.
How to use
- 1Choose a direction. Pick Encrypt to scramble plain text, or Decrypt to unscramble rail fence ciphertext.
- 2Set the rails. Enter the number of rails (the key). Both sides must use the same rail count - 3 is the classic choice.
- 3Type or paste your text. The result updates instantly in the panel beside it, and the fence preview shows the zigzag.
- 4Copy the result. Copy the output to use it, or switch to Decrypt with the same rails to confirm it round-trips.
Who it's for
- Students and teachers learning classical cryptography who want to see the zigzag pattern, not just the answer.
- Puzzle and escape-room makers encoding clues that are easy to solve by hand with the right rail count.
- CTF and cipher-challenge players decrypting rail fence text and trying different rail counts quickly.
- Anyone curious about ciphers who wants to encrypt a short message and check that it decrypts back exactly.
FAQ
Is this rail fence cipher tool free?
Yes - it's completely free with no sign-up and no limits. Both encryption and decryption run entirely in your browser.
Is my text uploaded anywhere?
No. Your text is processed locally in your browser and never sent to a server, so it stays private even for the messages you are testing.
What are rails in the rail fence cipher?
Rails are the rows the message is written across. The text starts on the top rail, steps down to the bottom rail, bounces back up, and repeats in a zigzag. The number of rails is the cipher's only key.
How do I decrypt a rail fence cipher without the key?
The key is just the number of rails, and there are very few sensible values. Try each rail count from 2 upward and read the outputs - the one that produces readable text is the answer. That is why the cipher offers almost no real security.
Does it keep spaces and punctuation?
Yes. The rail fence cipher only reorders characters, so spaces, punctuation, accents and emoji are all kept and moved along with the letters. Decrypting with the same rail count restores everything exactly.
Is the rail fence cipher secure?
No. It is a teaching and puzzle cipher, not real encryption. Because the key is only the rail count, anyone can break it in seconds by trying each value. Use it for learning and games, never to protect sensitive data.
What is the difference from the Caesar cipher?
The Caesar cipher is a substitution cipher: it replaces each letter with another. The rail fence is a transposition cipher: it keeps the same letters but changes their order. They are often taught together as the two basic cipher families.