Skip to main content

Cryptography & Ciphers

Rail Fence Cipher Decoder

Decode a rail fence cipher with a known rail count and offset. Restore zigzag text in your browser.

Tool workspace

Your input stays in this browser.

Add the required input to continue.

Needs input

You can run the tool again after any change.

Options

Number of zigzag rows. Use a whole number from 2 to the input length.

Steps into the zigzag before the first character. Start with 0.

Your result appears here

Decode a rail fence cipher with a known rail count and offset. Restore zigzag text in your browser.

This tool runs open-source code from CyberChef by GCHQ (Apache License 2.0). See open-source credits.

The decoder reconstructs the zigzag rows and reads characters in their original order.

The result contains the restored character sequence.

  • Check the answer to a rail fence exercise from a textbook or worksheet.

Sources: A Book on Classical Cryptography: railfence

Recover DEFENDTHEEASTWALL

Input: DNETLEEDHESWLFTAA

Settings: Rails 3 and Offset 0.

Result: DEFENDTHEEASTWALL

Rail Fence Cipher Decoder with Rails 2 turns the same input into DENSEWTLLFETEADAH. Unreadable output of the right length usually means the rail count is wrong.

Supply the original rail count and offset

  1. Paste ciphertext with its original spaces and punctuation.
  2. Remove grouping spaces added after encoding.
  3. Set Rails and Offset to the sender’s values.
  • The decoder does not search unknown settings.
  • UTF-16 code units can split an emoji.
  • Rail fence does not protect secrets.