Skip to content
D DocNectar

Free Rail Fence Cipher Encoder and Decoder

Encrypt or decrypt text with a rail fence cipher by writing it in a zigzag pattern across a chosen number of rails.

100% Free No Signup Works on all devices

Last updated October 12, 2026 · Report an error

Thanks for rating!

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.

  1. Enter mode.
  2. Enter text.
  3. Enter number of Rails.
  4. 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.

Frequently asked questions

Yes, with no signup and no limit on how many conversions you run.
They're removed before encrypting, since the zigzag pattern only works cleanly on a continuous stream of letters.
No — with a short message, an attacker can often try every rail count until the text becomes readable. It's used for puzzles and teaching, not real security.
Any number from 2 up to (but not including) the length of your text — more rails create a more scrambled arrangement, but there are more to try when guessing.

Get new calculators and guides in your inbox

No spam — just new tools like Rail Fence Cipher Tool and practical guides.

Favorites