You are on page 1of 2

Experiment No.

8
Rail fence technique

The rail fence cipher (also called a zigzag cipher) is a form of transposition cipher. It derives its
name from the way in which it is encoded.

To encrypt a message using the Rail Fence Cipher, you have to write your message in zigzag
lines across the page, and then read off each row. Firstly, you need to have a key, which for
this cipher is the number of rows you are going to have.

Encryption

In a transposition cipher, the order of the alphabets is re-arranged to obtain the cipher-
text.
 In the rail fence cipher, the plain-text is written downwards and diagonally on
successive rails of an imaginary fence.
 When we reach the bottom rail, we traverse upwards moving diagonally, after
reaching the top rail, the direction is changed again. Thus the alphabets of the
message are written in a zig-zag manner.
 After each alphabet has been written, the individual rows are combined to obtain
the cipher-text.

For example, if the message is “GeeksforGeeks” and the number of rails = 3 then cipher
is prepared as:
The rail fence cipher (sometimes called zigzag cipher) is a transposition cipher that
jumbles up the order of the letters of a message using a basic algorithm.
The rail fence cipher works by writing your message on alternate lines across the page,
and then reading off each line in turn.
For example, let’s consider the plaintext “This is a secret message”.

To encode this message we will first write over two lines (the “rails of the fence”) as
follows:

Note that all white spaces have been removed from the plain text.

The cipher text is then read off by writing the top row first, followed by the bottom row:

You might also like