# Rail Fence (ZigZag) Cipher

Encode, decode, visualize, and brute-force the Rail Fence transposition cipher. See the zigzag rail grid and try all rail counts to crack a ciphertext.

> Canonical page: https://elysiatools.com/en/tools/zigzag-railfence-text

- **Category:** Text Processing

- **Keywords:** rail fence, zigzag cipher, transposition cipher, classical cipher, decode, brute force

## Overview

The Rail Fence cipher is a classical transposition cipher that scrambles text by writing it in a zigzag pattern across N horizontal rails, then reading each rail top-to-bottom. This tool encodes plaintext, decodes ciphertext back, renders the visual zigzag grid so you can see how characters map to rails, and brute-forces rails 2–10 to help you crack an unknown rail count. Unlike substitution ciphers, rail fence preserves all the original letters — it only reorders them, so frequency analysis is useless against it; the attack is trying rail counts.

## Inputs

- **Text** (textarea): e.g. WEAREDISCOVERED
- **Mode** (select)
- **Number of rails** (number)

## When to use

- Encode plaintext with a selected number of rails for classical cipher exercises.
- Decode Rail Fence ciphertext when the rail count is known.
- Visualize the zigzag grid or try rail counts from 2 to 10 when the rail count is unknown.

## How it works

- Enter the plaintext or ciphertext in the Text field.
- Choose Encode, Decode, Visualize, or Brute-force mode.
- Set the number of rails from 2 to 20 for encoding, decoding, or visualization.
- The tool returns the transformed text, zigzag grid, or brute-force results as HTML.

## Use cases

- Practice classical cryptography and learn how transposition ciphers rearrange text.
- Check a known Rail Fence encoding or recover plaintext from ciphertext with a specified rail count.
- Compare possible rail counts when analyzing a ciphertext with an unknown configuration.

## Frequently asked questions

### What is the Rail Fence cipher?

It is a transposition cipher that writes text in a zigzag across horizontal rails and then reads the rails from top to bottom.

### How many rails can I use?

You can select between 2 and 20 rails for standard operations.

### What does brute-force mode do?

It tries rail counts from 2 through 10 to help identify a possible decoding.

### Does the cipher change the characters?

No. Rail Fence preserves the original characters and only changes their order.

### Can I see how the characters move between rails?

Yes. Visualize mode displays the zigzag rail grid and shows the character layout.

## Related tools

- [Extended Text Base Codecs (Base65536 + netstring)](https://elysiatools.com/en/tools/extended-text-base-codecs): Encode and decode with less-common text codecs: Base65536 (binary → dense Unicode) and netstring (self-delimiting framing). Base85 is intentionally not rebuilt (already covered).
- [Leet Speak Converter](https://elysiatools.com/en/tools/leet-speak-converter): Convert text to and from leet speak (1337). Encode with Basic, Full, or Caps styles, or decode leet back to plain text.
- [A1Z26 Letter-Number Workbench](https://elysiatools.com/en/tools/a1z26-letter-number-workbench): Convert between letters and numbers (A=1, B=2, … Z=26) with configurable separator and case, decode numbers back to letters, and compute the letter sum of any text.
- [ASCII85 Converter](https://elysiatools.com/en/tools/ascii85-converter): Encode and decode text to/from ASCII85 format (Adobe version)
- [Base32 Converter](https://elysiatools.com/en/tools/base32-converter): Encode and decode text to/from Base32 format with multiple variants
- [Base45 Converter](https://elysiatools.com/en/tools/base45-converter): Encode and decode text to/from Base45 format (RFC 9285)
- [Base58 Converter](https://elysiatools.com/en/tools/base58-converter): Encode and decode text to/from Base58 format with Bitcoin and Ripple variants
- [Base62 Converter](https://elysiatools.com/en/tools/base62-converter): Encode and decode text to/from Base62 format (0-9, A-Z, a-z)

## Samples

- [Copyright-Free MP3 Audio Samples](https://elysiatools.com/en/samples/mp3-samples): Collection of royalty-free audio samples for testing and development purposes including nature sounds, meditation music, and ambient audio
- [Web Image Processing Python Samples](https://elysiatools.com/en/samples/web-image-processing-python): Web Python image processing examples using PIL/Pillow including reading, saving, resizing, and format conversion
- [Android Image Processing Java Samples](https://elysiatools.com/en/samples/android-image-processing-java): Android Java image processing examples including reading/saving images, scaling, and format conversion
- [Android Image Processing Kotlin Samples](https://elysiatools.com/en/samples/android-image-processing-kotlin): Android Kotlin image processing examples including reading/saving images, scaling, and format conversion
