My Tools Garage

Rail Fence Cipher

Encrypt and decrypt with the zig-zag transposition cipher.

in-browser

How to use

  1. 1 Choose Encrypt or Decrypt.
  2. 2 Set the number of rails (the key) — at least 2.
  3. 3 Type or paste your text into the input box.
  4. 4 Copy the scrambled or recovered text from the output.

About Rail Fence Cipher

The Rail Fence Cipher is a classic transposition cipher that scrambles a message by writing it diagonally across a number of imaginary rails in a zig-zag, then reading the letters off rail by rail.

This tool lets you encrypt or decrypt any text simply by choosing how many rails to use — the more rails, the more the letters are shuffled.

Because it rearranges characters rather than substituting them, the ciphertext contains exactly the same letters as the original, just in a jumbled order.

It is a wonderful teaching example.

Unlike a Caesar or substitution cipher, the Rail Fence shows how transposition works: nothing about each letter changes, yet the message becomes unreadable until you know the rail count, which acts as the key.

Decryption reverses the zig-zag perfectly, so encrypting with three rails and decrypting with three rails returns your original text every time.

Spaces and punctuation are kept as part of the message, so you can see exactly how every character moves.

All processing runs locally in your browser.

Your text is never sent over the network or stored, making it safe for experimenting with private notes, and the tool works offline once the page has loaded.

FAQ

How secure is the Rail Fence cipher?

It is a historical cipher meant for learning and puzzles, not real security. With few rails it is easily cracked, so never use it to protect sensitive data.

Why must I use the same number of rails to decrypt?

The rail count is the key. Decrypting with a different number of rails reconstructs a different zig-zag, so you only recover the original message when the counts match.