Definitions

# Rail Fence Cipher

The Rail Fence Cipher (also called a zigzag cipher) is a form of transposition cipher that derives its name from the way in which it is encoded. In the rail fence cipher, the plaintext is written downwards and diagonally on successive "rails" of an imaginary fence, then moving up when we reach the bottom rail. When we reach the top rail, the message is written downwards again until the whole plaintext is written out. The message is then read off in rows. For example, if we have 3 "rails" and a message of 'WE ARE DISCOVERED. FLEE AT ONCE', the cipherer writes out:
`W . . . E . . . C . . . R . . . L . . . T . . . E`
`. E . R . D . S . O . E . E . F . E . A . O . C .`
`. . A . . . I . . . V . . . D . . . E . . . N . .`

Then reads off to get the ciphertext:

`WECRL TEERD SOEEF EAOCA IVDEN`

(A number of websites have mistakenly referred to a row-first complete rectangular transposition as being the Rail Fence - this seems to be a recent innovation. All of the older references are consistent in applying Rail Fence to this down-and-up transposition.)

## Problems with the Rail Fence Cipher

The rail fence cipher is not very strong; the number of practical keys is small enough that a cryptanalyst can try them all by hand.