〰️ Rail fence cipher

Your message zigzags across several rails, then gets read off line by line.

The result appears here in real time

Turn this message into a real game: create a virtual lock your players must crack open.

The rail fence cipher doesn't replace a single letter — it only changes their order. The message is written in a zigzag across 2 to 5 lines (the "rails"), then each rail is read left to right to form the final coded text. Same letters, completely different order.

It's a transposition cipher, a different family from the Caesar cipher or Atbash, which both swap letters out. Used in various forms since antiquity, it gets its modern name from how the zigzag pattern resembles a wooden railway fence when drawn out.

For a treasure hunt, the rail fence has a great teaching moment built in: it shows that simply scrambling the order of letters is enough to make a message unreadable, without changing a single one of them. A simple idea that always surprises kids the first time.

How to use it

  1. Type your message into the input field.
  2. Choose the number of rails (2 to 5) to set the difficulty.
  3. Copy the zigzag text or print the rail diagram.
  4. Hide the coded message and let your players rebuild the zigzag.

Example(Rails : 3)

Plain message

KEEP SEARCHING

Coded message

KSCGEPERHNEAI

Frequently asked questions

How do you decode a rail fence message without a diagram?

It's possible but tricky: you have to guess the number of rails used, then rebuild the zigzag letter by letter. With the diagram in hand, though, you just slot each letter back into its spot and read the message in seconds.

What's the difference between transposition and substitution?

Substitution (like the Caesar cipher) swaps each letter for a different one. Transposition (like the rail fence) keeps the same letters but changes their order. Some historical ciphers even combine both techniques to boost security.

Can a rail fence message become a digital lock?

Yes — on CrackAndReveal you create a lock whose expected answer is the word rebuilt from the zigzag. Players put the letters back in order, type their answer online, and the lock opens automatically.

Does adding more rails make the message harder to crack?

Yes, up to a point: with 2 rails, the zigzag is easy to spot at a glance, while with 4 or 5 rails, the letter order becomes far less obvious — without becoming unreadable for a motivated kid.

More secret codes

Now hide this message behind a lock

With CrackAndReveal, your coded message becomes a virtual lock to crack: players decipher your code, enter the solution and reveal your surprise.

Create a free lock
Rail Fence Cipher: Zigzag Encoder & Decoder | CrackAndReveal