Rail fence – the simplest transposition cipher
Rail fence cipher lays out characters in a zigzag pattern across a number of “rails” and reads them off row by row.
Definition
The Rail fence cipher is a transposition cipher. As such it is a method that rearranges the characters in a message in a particular way without changing them. Here, the message is written down in a zigzag pattern across some rows or “rails” and then read off row by row to form the ciphertext.
How does the Rail fence cipher work?
To encrypt the message “We are discovered. Run at once.” we lay out the letters without spaces and punctuation in a zigzag pattern across a certain number of “rails”, starting in the top left corner.
After that, we simply read off the letters row by row and put them together to get the following ciphertext:
To decode, we fill in the ciphertext in the same zigzag pattern row by row, then read off the plaintext column by column.
The number of rails you use and the initial offset (number of columns you skip before laying out the message) form the key of the cipher. In this example, we use 3 rails and no initial offset.