AZ Tools

Rail Fence Cipher Encoder & Decoder

Text

The Rail Fence cipher is a classic transposition cipher: the letters of a message are written diagonally in a zigzag pattern down and up across a fixed number of rails, then read off one row at a time to form the ciphertext. Unlike substitution ciphers, every letter is kept — only their order changes. Pick the number of rails (the key), type or paste your text, and switch between encode and decode. Because the pattern is fully reversible, decoding with the same rail count restores the original. Everything is computed locally in your browser.

Mode
Result

How to use

  1. Choose Encode or Decode.
  2. Set the number of rails (2 or more) — this is the key.
  3. Type or paste your message or ciphertext.
  4. Read the result and copy it. Decoding with the same rail count reverses encoding.

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.

Related tools