BYTETOOLS

Rail Fence Cipher Encoder & Decoder

Encode and decode text with the rail fence transposition cipher using 2 to 10 rails, with an optional zigzag visualization of the rail pattern.

Rail pattern

W...E...C...R...L...T...E
.E.R.D.S.O.E.E.F.E.A.O.C.
..A...I...V...D...E...N..

Result

WECRLTEERDSOEEFEAOCAIVDEN

  • Encode and decode with 2 to 10 rails
  • Zigzag transposition that reorders letters
  • Optional visual of the rail pattern
  • Live output as you type
  • One-click copy of the result
  • Fully browser-based and private

How to use the Rail Fence Cipher Encoder & Decoder

  1. 1

    Choose Encode or Decode.

  2. 2

    Set the number of rails from 2 to 10.

  3. 3

    Type or paste your message into the text box.

  4. 4

    Read the transformed text update instantly below.

  5. 5

    Turn on the visualization to see the zigzag rail pattern.

About the Rail Fence Cipher Encoder & Decoder

The ByteTools Rail Fence Cipher scrambles text with a classic transposition method: letters are written in a zigzag across a chosen number of rails, then read off row by row. Unlike substitution ciphers it never changes the letters themselves, only their order.

Choose between 2 and 10 rails, switch between encode and decode, and turn on the visualization to see exactly how your message weaves down and up the fence. It is a great hands-on way to teach transposition and a fun puzzle for escape rooms and CTFs.

Everything runs locally in your browser with JavaScript, so no text is uploaded or stored. Copy the scrambled or recovered message to your clipboard whenever you like.

Frequently asked questions

What is a rail fence cipher?

The rail fence cipher is a transposition cipher that writes your message in a zigzag pattern across several rows, called rails, then reads it off one row at a time. The letters stay the same but their order is scrambled, hiding the message.

How does the number of rails affect the cipher?

More rails create a deeper zigzag and a more thorough scramble, while two rails give a simple alternating pattern. The number of rails is effectively the key, so encoder and decoder must use the same value to match.

How do I decode a rail fence message?

Switch to decode and set the same number of rails used to encode. The tool rebuilds the zigzag pattern, places the ciphertext letters back onto the rails, and reads them in zigzag order to recover the original message.

Does the rail fence cipher change the letters?

No. Being a transposition cipher, it only rearranges the positions of the characters and never substitutes one letter for another. That is why a decoded message contains exactly the same letters as the original, just reordered.

Is the rail fence cipher secure?

Not by modern standards. With only a handful of practical rail counts, it can be brute-forced quickly, and the letter frequencies are unchanged. It is best treated as an educational example of transposition or as a light puzzle.

Related tools