Want to keep learning?

This content is taken from the Purdue University's online course, World of Spies: Keeping Secrets. Join the course to learn more.
Picture of a rail fence

Transposition ciphers

Transposition Ciphers

Simple substitution ciphers directly substitute one letter of the alphabet with another letter or character. In a transposition cipher, the letters in the message stay the same; however, the text is scrambled based upon a predetermined pattern.

Rail Fence Cipher

One common type of transposition cipher is a rail fence cipher. Look at the shape of the top of the rail fence above. Notice how it creates an up, down, up, down, “W” pattern.

In this type of cipher, the message is written in this pattern within a table with a predetermined number of rows and columns. The “key” will determine the number of rows, and the number of characters in the message will determine the number of columns. (Ideally, the number of characters in the message will be at least three times the key.)

To encipher the message, create the table. Write the first letter of your message in the upper left-hand corner. Move one square over (to the right) and one square down. Write the next letter. Continue using this pattern until you reach the bottom of the table. Then, move one square over and one square up to complete a “V” pattern. Continue with this pattern until you have entered the entire message.

The message “Please help me” with a key of 4 would look like this:

Example of rail fence cipher

To encipher the message, write the characters as they appear in each row. The ciphertext for this message using this key would look like this:


To decipher this message, create a blank table using the key to determine the number of rows. Since the key for this message is four, we would need four rows. Count the number of characters in the ciphertext to determine the number of columns. Next, add dashes in the table where the plaintext would go. Begin replacing the dashes with the ciphertext by rows, moving left to right. In this example, we have replaced the first two dashes with the first two letters of the ciphertext. We would continue to replace the dashes in each row with the ciphertext until the message appears.

Example of rail fence deciphering process

One variation of the rail fence cipher involves adding blank spaces in between the words of the plaintext message.

Example of rail fence cipher with blank spaces between words

In this case, the blank spaces are counted as characters, and they are included in the ciphertext like this:

Ciphertext: P MLEH EESEP AL

One other variation is to replace the blank spaces with nulls. Nulls are characters that aren’t part of the message. In the following example, we have replaced the spaces between the words with x’s. We have also added nulls to the end of the message to make it easier for the recipient to decipher. Unfortunately, by creating a pattern of x’s, we have also made it easier for others to decipher as well.

Example of rail fence cipher with nulls


There are many sites that will allow you to encode and decode messages by entering information into an applet. These applets should give you an idea of how easy it is to break these types of ciphers using computer programs. (One example is listed in the “See Also” section below.) We will talk more about how computers are used to facilitate data analysis next week.

Route Cipher

Another type of transposition cipher is a route cipher. In this cipher, the message is written in a table from top to bottom, filling all spaces in the first column before moving on to the next. Again, you can add spaces or nulls between words or at the end of the message to complete the table.

Example of Route Cipher

For this example, the plaintext is still “Please help me.” However, the ciphertext is now PAHPLSEMEELE.

Share this article:

This article is from the free online course:

World of Spies: Keeping Secrets

Purdue University