Privacy Canada is community-supported. We may earn a commission when make a purchase through one of our links. Learn more.

Rail Fence Cipher

Ludovic Rembert
Last Updated on August 15, 2021
rail fence cipher

The rail fence cipher is a simple type of transposition cipher. It’s also aptly named the zigzag cipher due to the way the encryption occurs—plaintext characters are mixed up in a zigzag manner.

This cipher has little to no security as the resultant ciphertext is an anagram. Thus, someone with a piece of paper and a pencil could easily break the cipher.

Nonetheless, the rail fence cipher may have some utility when it’s combined with another type of cipher. For example, combining the rail fence cipher with a substitution cipher could provide more security as someone would have to break each cipher separately.

Cipher Example

To use the rail fence cipher, you need to decide how many “rails” you want to use. It’s most common to use three rails, or three lines. This is shown below with the plaintext “Escape now.”


Now, to create the ciphertext, you simply read off the characters horizontally. The resultant ciphertext is “EPWSAEOCN”.

If you were to use four rails, you would get the following table.


The ciphertext from this version is “ENSEOCPWA”, slightly different.



Breaking the rail fence cipher is relatively easy for a cryptanalyst.

They only need to find the key, or the number of rails, by guessing several numbers and manually trying each. Alternatively, to find the key, a cryptanalyst can guess some of the plaintext using anagramming.

The Bottom Line

The rail fence cipher is a simple transposition cipher that offers virtually no security as no characters are substituted. Thus, it can be broken by a computer in microseconds, and it doesn’t qualify as a secure method of hiding a message or password.

If you’re concerned about your online safety and want to ensure you have secure passwords, try out the Strong Password Generator from Privacy Canada.  

You Might Also Like:
Related posts