The rail fence cipher is a simple transposition cipher. It is also known as a zigzag cipher. The name comes from the way letters are arranged. In a rail fence cipher, the plaintext letters are written diagonally in a up-down pattern from left to right. The message is then read row-by-row from top to down. The number of rows can vary, and so can also the starting place for the first letter.

Rail fence cipher

Rail fence layout


            

Features

Rail fence cipher, and variants of it, are sometimes used in easy geocaching mystery caches, and easy logic puzzles. It can easily be detected by statistical methods, but it's usually easiest and quickest to just try every possible key manually ("brute force attack").

Rail fence
Rail fence

Sample text

CBKOERAIGDEN

The ciphertext above represents "CODEBREAKING" encrypted using 3 rails and 0 offset.

C   B   K   
O E R A I G
D E N

See also: Code-Breaking tools | Adfgvx cipher | Adfgx cipher | Affine cipher | Atbash cipher | Baconian cipher | Beaufort cipher | Bifid cipher | Caesar cipher | Columnar transposition | Cryptogram | Double transposition | Enigma machine | Four-square cipher | Gronsfeld cipher | Keyed caesar cipher | One-time pad | Pigpen cipher | Playfair cipher | Rot13 | Route transposition | Substitution cipher | Trifid cipher | Variant beaufort cipher | Vigenere cipher