Rail fence cipher encoder

A transposition cipher popular in puzzles and scout challenges. It is a puzzle cipher, not a security tool.

Loading the tool…

Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.

How to use it

  1. Enter text, rails and remove spaces and line breaks first.
  2. The result appears straight away and updates as you edit.
  3. Copy the result, or copy a link that keeps the same values to share it.

How it is calculated

Character i goes on rail p = i mod (2(n - 1)) if p is below n, otherwise on rail 2(n - 1) - p. The rails are then read from first to last.

Example

Inputs: Rails = 3, Remove spaces and line breaks first = no. Result: Encoded text: WECRUOERDSOEERNTNEAIVDAC; Characters: 24.

WEAREDISCOVEREDRUNATONCE
WECRUOERDSOEERNTNEAIVDAC

Limits and caveats

  • This is a puzzle and teaching cipher that is easy to break, so never use it to protect passwords or sensitive data.
  • Spaces and symbols are moved like any other character unless you turn on space removal.

Questions about this tool

Do the letters themselves change?

No. The rail fence only reorders characters, so each letter count stays the same.

What if there are more rails than characters?

The text comes out unchanged, because each character sits on its own rail.

Should I remove spaces?

Classic puzzles remove them. If you keep them, they move with the text and return to place on decoding.