Sunteți pe pagina 1din 8

Rail Fence Cipher

1. Cipher Activity
2. Introduction
3. Encryption
4. Decryption
5. Discussion
6. Exercise

The railfence cipher is an easy to apply transposition cipher that jumbles up the order of the letters of
a message in a quick convenient way. It also has the security of a key to make it a little bit harder to
break.
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, the plaintext "defend the east wall" is written as shown
below, with all spaces removed.

The simplest Rail Fence Cipher, where each letter is written in a zigzag pattern across the page.
The ciphertext is then read off by writing the top row first, followed by the bottom row, to get
"DFNTEATALEEDHESWL".
Encryption
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. You then start writing the letters of the plaintext diagonally
down to the right until you reach the number of rows specified by the key. You then bounce back up
diagonally until you hit the first row again. This continues until the end of the plaintext.
For the plaintext we used above, "defend the east wall", with a key of 3, we get the encryption process
shown below.
The Rail Fence Cipher with a key of 3. Notice the nulls added at the end of the message to make it the right
length.
Note that at the end of the message we have inserted two "X"s. These are called nulls, and act as
placeholders. We do this to make the message fit neatly in to the grid (so that there are the same
number of letters on the top row, as on the bottom row. Although not necessary, it makes the
decryption process a lot easier if the message has this layout.
The ciphertext is read off row by row to get "DNETLEEDHESWLXFTAAX".
Decryption
The decryption process for the Rail Fence Cipher involves reconstructing the diagonal grid used to
encrypt the message. We start writing the message, but leaving a dash in place of the spaces yet to
be occupied. Gradually, you can replace all the dashes with the corresponding letters, and read off the
plaintext from the table.
We start by making a grid with as many rows as the key is, and as many columns as the length of the
ciphertext. We then place the first letter in the top left square, and dashes diagonally downwards
where the letters will be. When we get back to the top row, we place the next letter in the ciphertext.
Continue like this across the row, and start the next row when you reach the end.
For example, if you receive the ciphertext "TEKOOHRACIRMNREATANFTETYTGHH", encrypted with
a key of 4, you start by placing the "T" in the first square. You then dash the diagonal down spaces
until you get back to the top row, and place the "E" here. Continuing to fill the top row you get the
pattern below.

The first row of the decryption process for the Rail Fence Cipher. We have a table with 4 rows because the key is
4, and 28 columns as the ciphertext has length 28.
Continuing this row-by-row, we get the successive stages shown below.

The second stage in the decryption process.

The third stage in the decryption process.

The fourth and final stage in the decryption process.


From this we can now read the plaintext off following the diagonals to get "they are attacking from the
north".
Discussion
The Rail Fence Cipher is a very easy to apply transposition cipher. However, it is not particularly
secure, since there are a limited number of usable keys, especially for short messages (for there to be
enough movement of letters, the length of the message needs to be at lease twice the key, but
preferably 3 times the key). You could process these quite quickly by hand, and even more quickly
with a computer.
The use of nulls can also have a detrimental effect on the security of the cipher, as an interceptor can
use them to identify where the end of the line is, and so have a sensible guess at the key. This can be
averted by using a more common letter, such as "E", to fill the null spaces, as it will still be clear to the
recipient that these are not part of the message as they will appear at the end of the plaintext. The
Rail Fence Cipher can also be utilised without the use of nulls.
One way to also make the encryption a little bit more secure, is to keep the spaces as characters, and
include them in the encryption table. They are treated in exactly the same way as any other letter. For
example, using the plaintext "defend the east wall" with a key of 3 again, but this time including
spaces we get the table below.

The Rail Fence Cipher with spaces left in the message. Colour is used to emphasise where spaces are, against
the blank squares of the table.
So the ciphertext would read "DNHAWXEEDTEES ALF TL".

Route Cipher
1. Introduction
2. Encryption
3. Decryption
4. Discussion
The Route Cipher is a transposition cipher where the key is which route to follow when
reading the ciphertext from the block created with the plaintext. The plaintext is written in a
grid, and then read off following the route chosen
Encryption
First we write the plaintext in a block of reasonable size for the plaintext. Part of your key is
the size of this grid, so you need to decide on either a number of columns or number of rows
in the grid before starting. Once the plaintext is written out in the grid, you use the Route
assigned. This could be spiralling inwards from the top right corner in a clockwise direction,
or zigzagging up and down.
As an example, lets encrypt the plaintext "abort the mission, you have been spotted". First we
need to decide on the number of columns we are going to use, lets say 5.
Notice how we have used nulls at the end of the message to
make a nice rectangle.
We then choose which route we want to use to encrypt the
message.

The plaintext written in a grid with 5 columns.


With a route of reading down the columns we get the ciphertext: "ATSYV NTBHS OESEO
EIUBP DRMOH EOXTI NAETX".
With a route of spiralling inwards counter-clockwise from the bottom right we get: "XTEAN
ITROB ATSYV NTEDX OEHOM EHSOE SPBUI".
Decryption
To decrypt a message received that has been encoded with the Route Cipher, we need to
know the route used and the width or height of the grid. We then start by constructing a blank
grid of the right size, and then place the ciphertext letters in the grid following the route
specified.
For example, to decrypt the ciphertext "RAEWE CREDX ESIDO V" with the route spiral
inwards counter-clockwise from the top right, with a grid width of 4, we follow the process
shown below

We start by drawing a grid that is 4x4, We at the top right square, and begin to Continue in the spiralling direction until
since the width is 4, and there are 16 spiral inwards in a counter-clockwise the whole ciphertext is placed in the grid.
characters in the ciphertext. direction.
Now, reading off the plaintext we get "We are discovered".
Discussion
The Route Cipher is easy to use to jumble up a message very quickly. It has some problems
depending on what route you pick as you can end up with large chunks of plaintext in the
right order within the ciphertext (or simply reversed) which gives away alot about the width
of the grid and the route used. Careful selection of the route is important.
However, for a suitably lengthy message, there are potentially infinitely many different routes
that could be taken through the grid. It is limited only by imagination and ease of
communication of the route.
An historical use of the Route Cipher was the Union Route Cipher used by the Union forces
during the American Civil War. Rather than transposing letters by the given route, it moved
whole words around. Some words, of vital importance were not protected in this way, so they
were first encoded using a codeword. Sometimes, the cipher clerks would even add whole
null words to the ciphertext, often making the message humorous.

Columnar Transposition
Columnar Transposition involves writing the plaintext out in rows, and then reading the
ciphertext off in columns. In its simplest form, it is the Route Cipher where the route is to
read down each column in order. For example, the plaintext "a simple transposition" with 5
columns looks like the grid below
If we now read down each column we get the ciphertext
"ALNISESTITPIMROOPASN".

Plaintext written across 5 columns.


So far this is no different to a specific route cipher. Columnar Transposition builds in a
keyword to order the way we read the columns, as well as to ascertain how many columns to
use.
Encryption
We first pick a keyword for our encryption. We write the plaintext out in a grid where the
number of columns is the number of letters in the keyword. We then title each column with
the respective letter from the keyword. We take the letters in the keyword in alphabetical
order, and read down the columns in this order. If a letter is repeated, we do the one that
appears first, then the next and so on.
As an example, let's encrypt the message "The tomato is a plant in the nightshade family"
using the keyword tomato. We get the grid given below.
We have written the keyword above the grid of the
plaintext, and also the numbers telling us which
order to read the columns in. Notice that the first
"O" is 3 and the second "O" is 4, and the same
thing for the two "T"s.

The plaintext is written in a grid beneath the keyword. The


numbers represent the alphabetical order of the keyword, and so the
order in which the columns will be read.
Starting with the column headed by "A", our ciphertext begins "TINESAX" from this
column. We now move to the column headed by "M", and so on through the letters of the
keyword in alphabetical order to get the ciphertext "TINESAX / EOAHTFX / HTLTHEY /
MAIIAIX / TAPNGDL / OSTNHMX" (where the / tells you where a new column starts). The
final ciphertext is thus "TINES AXEOA HTFXH TLTHE YMAII AIXTA PNGDL OSTNH
MX".
Decryption
The decryption process is significantly easier if nulls have been used to pad out the message
in the encryption process. Below we shall talk about how to go about decrypting a message in
both scenarios.
Firstly, if nulls have been used, then you start by writing out the keyword and the alphabetical
order of the letters of the keyword. You must then divide the length of the ciphertext by the
length of the keyword. The answer to this is the number of rows you need to add to the grid.
You then write the ciphertext down the first column until you reach the last row. The next
letter becomes the first letter in the second column (by the alphabetical order of the keyword),
and so on.
As an example, we shall decrypt the ciphertext "ARESA SXOST HEYLO IIAIE XPENG
DLLTA HTFAX TENHM WX" given the keyword potato. We start by writing out the
keyword and the order of the letters. There are 42 letters in the ciphertext, and the keyword
has six letters, so we need 42 6 = 7 rows.

We have the keyword and the order of the letters in the keyword. We also know there are 7 rows.
Now we start by filling in the columns in the order
given by the alphabetical order of the keyword,
starting with the column headed by "A". After the
first column is entered we have the grid shown to
the right.
We continue to add columns in the order specified
by the keyword.

After inserting the second column. After inserting the third column. The completely reconstructed grid.
Now we read off the plaintext row at a time to get "potatoes are in the nightshade family as
well".
When no nulls have been used we have to do a slightly different calculation. We divide the
length of the ciphertext by the length of the keyword, but this is likely to not be a whole
number. If this is the case, then we round the answer up to the next whole number. We then
multiply this number by the length of the keyword, to find out how many boxes there are in
total in the grid. Finally, we take the length of the ciphertext away from this answer. Thie
number (which should be less than the length of the key) is how many nulls there would have
been if used, so we need to black out these last few boxes, so we don't put letters in them
whilst decrypting.
To decrypt the ciphertext "ARESA SOSTH EYLOI IAIEP ENGDL LTAHT FATEN HMW",
we start similarly to above, by heading the columns with the keyword potato. This time, to
find how many rows we need, we do 38 6 = 6.3333. We round this up to the next number,
which is 7, so we need 7 rows. Whe we multiply 6 x 7 we get 42, and 42 - 38 = 4. Hence we
need 4 placeholders in the last row. We get the grid below to the left. After pluggin the
ciphertext letters in, in the same way as above, we get the grid on the right.

We write the keyword and order as above, but block out the last 4 After inserting the ciphertext column by column we get this grid.
spaces as we know these are not needed from the calculations done
above.
Finally, we read off the plaintext in rows, to reveal the same plaintext as the other example,
"potatoes are in the nightshade family as well".
Discussion
Columnar Transposition has the security of a transposition cipher with the extra befefit of
utilizing a keyword. This is easier to remember than some complex route, and provides a
better mixing effect than the railfence cipher.
One of the key benefits of a transposition cipher over a substitution cipher is that they can be
applied more than once. For example, the Columnar Transposition cipher could be applied
twice on the plaintext. This is done by following the process above to produce some
ciphertext, but then to use the same (or a different) keyword and to plug this ciphertext into
the grid and read off the rows again. Our example above would give us

We put the plaintext into the grid below the keyword tomato to get We now write the ciphertext retrieved from the grid to the left in
the ciphertext "TINES AXEOA HTFXH TLTHE YMAII AIXTA the grid in rows as if it was the plaintext.
PNGDL OSTNH MX"
After this double transposition, we get the ciphertext "EATMX DHNOH YIGNI EXEAN
TATTI AOXTX FHIPS SHLAT LM".
This double transposition increases the security of the cipher significantly. It could also be
implemented with a different keyword for the second iteration of the cipher. In fact, until the
invention of the VIC Cipher, Double Transposition was seen as the most secure cipher for a
field agent to use reliably under difficult circumstances.

S-ar putea să vă placă și