Last updated October 12, 2026 · Report an error
The rail fence cipher is a transposition cipher — instead of replacing letters like a substitution cipher, it rearranges them by writing the message in a zigzag pattern across several rows.
This tool encrypts or decrypts text using a rail fence cipher with a number of rails you choose.
How it works
Enter your text and a number of rails (rows). The text is written diagonally down and up across that many rows in a zigzag, then the ciphertext is formed by reading each row left to right, top to bottom. Decryption reconstructs the same zigzag pattern to figure out which row each ciphertext letter came from. Spaces are removed before processing.
- Enter mode.
- Enter text.
- Enter number of Rails.
- Click Calculate to see your results.
Examples
3 rails
"WEAREDISCOVEREDFLEEATONCE" written across 3 rails and read off row by row becomes "WECRLTEERDSOEEFEAOCAIVDEN".
Who should use it
- Puzzle and escape-room style word games.
- Teaching the difference between substitution and transposition ciphers.
Industry applications
- Cryptography education
- Games and puzzles
Advantages
- Simple to do by hand with just pen and paper.
- A clear introduction to transposition (rearranging), as opposed to substitution (replacing).
Limitations
- Only a handful of possible rail counts for any given message — easily brute-forced.
Common mistakes to avoid
- Using a rail count equal to or greater than the message length, which leaves the text unchanged or invalid — the tool flags this.
- Forgetting that the same rail count must be used for both encrypting and decrypting.
Best practices
- Use the rail fence cipher for puzzles or teaching transposition ciphers — not for protecting real secrets.
Tips
- If you don't know the rail count used to encrypt a message, try every value from 2 up to the message length — one of them will produce readable text.