Coders Packet

Rail fence cipher in C++

By deepshikha

The Encrypted text using Rail Fence cipher in C++ is an easy to apply transposition cipher that jumbles up the order of the letters of a message in a quick convenient way.

It is a type of transposition cypher technique to encrypt the plain text message into a cypher text by rearranging the characters of the plain text. The alternate characters are picked first, starting from the first character. The Rail Fence cypher works by writing your message on alternate lines across the page and then reading off each line in turn. 


  • To encrypt plaintext in the Rail Fence Cipher technique, we have to write the plaintext in zig-zag lines across the rails, and then read off each rail. This plaintext is written in the downwards and diagonal direction on a successive rail of an imaginary fence.
  • When we have reached the bottom rail, we have to traverse upwards by moving in a diagonal direction, after we reached the top rail, the direction is changed again. Thus the alphabets of the plaintext are written in a zig-zag pattern.
  • After each alphabet has now written on the rail, the individual rows are combined to obtain the cypher-text.

For Example



Method - T.  S.  E.  A.  T.  O.  I.  G

                E   S   R   C.  C.  D.  N


Download Complete Code


No comments yet