NOTIFICATION: These examples are provided for educational purposes. The use of this code and/or information is under your own responsibility and risk. The information and/or code is given ‘as is’. I do not take responsibilities of how they are used.
The main idea of transposition ciphers is to rearrange the order of the letters used in the plaintext. This prevent the attacker to be able to recognise the message by using the frequency of distributions.
Rail Fence Cipher
The basic concept of encryption on Rail Fence cipher is the follow:
- Select a number of rows greater or equal to two. For this example, we will pick three:
- Place each letter of the message in each row, one letter at a time, on one row at a time, from the top to the bottom
- After finished, we append one row after another in order, forming the ciphertext.
The decryption of a rail fence cipher is almost the reverse process of the encryption.
- You will need the ciphertext and the number of rows:
- The ciphertext is “SEEEEAURCTSGPSRMSE”
- The number of rows is:
|rows| = 3
- Computer the length of the ciphertext. In this case, the ciphertext “SEEEEAURCTSGPSRMSE” is:
|ciphertext| = 18
- Lets calculate the columns that we will have:
Number of Columns = ( |ciphertext| ÷ |rows| ) + ( |ciphertext| mod |rows| )
= ( 18 ÷ 3 ) + (18 mod 3 )
= 6 + 0
= 6 columns
- Now, we have a table of 3 rows by 6 columns:
- Let fill up this table with the ciphertext, one letter at a time, from top to down and left to right:
- Now recreate the plaintext from this table: