Rail Fence Cipher Encoder + Decoder

The Rail Fence cipher writes plaintext in a zigzag pattern across N "rails", then reads off row-by-row. Classic transposition cipher — easy to break by brute force (just try 2-10 rails) but a fun puzzle cipher.

How to use the Rail Fence Cipher Encoder + Decoder

Pick encrypt/decrypt, set number of rails. The zigzag pattern visualization shows how the cipher works.

How the rail fence zigzag works

The rail fence is a transposition cipher: it does not change the letters, it rearranges their order. You write the plaintext diagonally down and up across a fixed number of rows — the rails — in a zigzag, then read the letters off one full row at a time to get the ciphertext. With three rails, the message bounces down to the bottom rail, back up to the top, and so on, distributing letters across the rows by position.

Because the only secret is the number of rails, it is trivial to break: an attacker just tries each rail count from two upward until readable text appears. That makes it useless for real security but a popular puzzle, escape-room, and CTF cipher, and a clear first example when teaching the difference between transposition and substitution. This tool encrypts, decrypts, and draws the zigzag so you can see the pattern.

Common use cases

  • Puzzles and escape rooms — encode a clue that solvers can crack with a little effort.
  • CTF challenges — create or solve a classic transposition step in a capture-the-flag.
  • Teaching cryptography — demonstrate transposition as distinct from substitution ciphers.
  • Decoding a known cipher — recover plaintext when you know or can guess the rail count.
  • Visualizing the method — watch the zigzag fill to understand how the letters scatter.

Frequently asked questions

Is the rail fence cipher secure?

No. The only key is the number of rails, so an attacker simply tries two, three, four, and so on until the text reads correctly. Treat it as a puzzle, never as protection for anything real.

How does the number of rails change the result?

More rails spread the letters across more rows before they are read off, scrambling the order differently. The recipient must use the same rail count to reconstruct the zigzag and recover the message.

What is a transposition cipher?

One that keeps the original letters but rearranges their positions, as the rail fence does. A substitution cipher instead replaces each letter with another, like Caesar or Vigenère.

Do spaces and punctuation matter?

They are placed on the rails like any other character, so keeping them can leak word lengths. Classic puzzles often strip spaces first; this tool processes the text as you enter it.
Embed this tool on your site

Free to embed, no attribution required (but appreciated). Paste this where you want the tool to appear: