Definition
Rain fence cipher refers to a transposition cipher that rearranges plaintext characters in a zigzag pattern across multiple rows or rails to encrypt it.
The rail fence cipher is sometimes confused with the zigzag cipher, a totally different concept as described by Fletcher Pratt in his book Secret and Urgent.
How the Rail Fence Cipher Works
To explain how the rail fence cipher works, take an example of plaintext and note it diagonally across rows (rails) in a zigzag pattern. Start with the first character in the top-left corner and continue with the next character in the row below.
Subsequent new characters should descend until you reach the bottom row. After that, reverse the direction with the characters climbing up rows diagonally.
Continue this process until the entire message is encoded. Finally, combine characters from each row to create nonsensical words and add them to the ciphertext. The cipher key is the number of rows that make up the pattern.
Here is a simple example. The plaintext message is TODAY, and the cipher key is 4:
- Row 1: Ta
- Row 2: oy
- Row 3: d
- Row 4: a
Combine these to form a ciphertext ‘Tayoda.’