Classical Crypto
Classical Crypto
Table of Contents
1- Substitution Cipher ............................................................................................................................. 2
1.1 Classical Monoalphabetic cipher ............................................................................................ 2
1.1.1 Ceaser Cipher .................................................................................................................. 2
1.1.2 Keyword Cipher ............................................................................................................... 3
1.1.3 Affine Cipher ................................................................................................................... 4
1.1.4 Multiliteral Cipher ........................................................................................................... 5
1.1.5 Simple Substitution ......................................................................................................... 6
1.1.6 Summary ......................................................................................................................... 6
1.2 Classical Polyalphabetic Cipher ............................................................................................... 7
1.2.1 Vigenere Cipher............................................................................................................... 7
1.2.2 Autokey Cipher................................................................................................................ 9
1.3 Polygraphic Ciphers................................................................................................................. 9
1.3.1 Playfair Cipher ................................................................................................................. 9
1.3.2 Hill Cipher ...................................................................................................................... 11
1.3.4 Summary ....................................................................................................................... 12
2 - Transposition Cipher: ....................................................................................................................... 12
2.1 Permutation Cipher............................................................................................................... 13
2.2 Column Permutation Cipher ................................................................................................. 14
2.3 Double-Transposition Cipher ................................................................................................ 15
2.4 Summary ............................................................................................................................... 15
References ........................................................................................................................................ 16
By : Jawid Arabzada (IIUM)
1- Substitution and transposition cipher:
Substitution Cipher
In substitution every letters of plain text are replaced by another letter , number or
symbol , each letter preserve its position but it changes the identity of the letter for
example Ceaser cipher.
Substitution ciphers are mainly divided in two parts, Monoalphabetic cipher
and Polyalphabetic cipher.
A B C D E F G H I J
0 1 2 3 4 5 6 7 8 9
K L M N O P Q R S T
10 11 12 13 14 15 16 17 18 19
U V W X Y Z
20 21 22 23 24 25
We use these formula to encrypt and decrypt the messages using Ceaser Cipher
Encryption: Ek(X) = x + K mod 26
Decryption: Dk(y) = y – K mod 26
By : Jawid Arabzada (IIUM)
Example 1.1
Suppose they key for a Ceaser Cipher is K =11 , and the plain text is
We will meet at midnight.
Firstly we convert the plain text to integer numbers using the above table we have and we
get w = 22, e = 4.
Our final result after converting is
22 4 22 8 11 11 12 4 4 19 0 19 12 8 3 13 8 6 7 19
After converting we use the formula for encrypting the message.
Encryption: Ek(X) = x + K mod 26
Ek(X) = 22 + 11 mod 26 = 7
Ek(X) = 4 + 11 mod 26 =15
And after we do this process for every single character we will get
7 15 7 19 22 22 23 15 15 4 11 4 22 19 14 24 19 17 18 4
And finally we substitute the letters according to its value from the table.
7 = H 15 = P …..4 =E
Our Cipher text is as follow
HPHTWWXPPELEXTOYTRSE
To decrypt the encrypted message we simply convert the cipher text to integer number
from the table given and we use the following formula.
Decryption: Dk(y) = y – K mod 26
7 = H 15 = P …..4 =E
Dk(y) = 7 – 11 mod 26 = 22
Dk(y) = 15 – 11 mod 26 = 4
We continue until we reach to the last letter and then simply substitute them from the
table.
Complexity of Ceaser Cipher is 25! and can be broken by brute force attack .
For example , we select keyword “magicnet” , the two alphabets can be written as follows :
A b c d e f g h I j k l m n o p q r s t u v w x y z
m a g I c n e t b d f h j k l o p q r s u v w x y z
These two alphabets define the keyword substitution pattern . with this keyword the
plaintext “a” is always replaced by m and “b” is always replaced by “a” .
For example let’s encipher “Help me “
we will have “tcho jc” .
Variation of this type of cipher were very popular in 14th-century in Europe . By 15th even
today, monoalphabetic keyword type is still around but only the new learners are using it.
Decryption
deciphering of keyword cipher is very easy what you need to know is the keyword
after writing keyword write the remaining alphabet letter and write a full alphabet
letter then just compare the matching .
C = ap + b (mod26)
For example we choose the key (7,3) . as we 7 is going to work because gcd (7,26) is 1.
Lets encipher the word “dot” using affine method. First we write the letters
By : Jawid Arabzada (IIUM)
A b c d e f g h I j k l m n o p q r s t u v w x y z
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
So with the given key and plain text , our ciphertext is “yxg”.
c o d e s
c a b c d e
By : Jawid Arabzada (IIUM)
o f g h i/j k
d i m n o p
e q r s t u
s v w x y z
Let’s solve an example using multiliteral cipher; we want to encipher the “hat”
We go the table we created and then check every letter for h, we find the letters that
intersect in “h” so h = OD, a = cc, and t = ee.
Finally our cipher text is “od cc ee”.
Decryption
The decoding process is very simple, a reverse look up to the matrix. To decrypt the cipher
text “od cc ee” we find the intersection of “od” and its h “cc” is a and “ee” is “t”.
1.1.6 Summary
Despite there is a number of classical monoalphabetic ciphers that have been for
use for a very long time. However, all of them have very common weaknesses and
By : Jawid Arabzada (IIUM)
that is the level of complexity because using the substation is very low and can be
broken very easily.
In the above table the row based Alphabet (vertical one) is used as the key and the column
based alphabet at the top of table is used as plain text. We will encrypt the above message
we gave. Plain text is “This is the plain text” and the keyword is “help”.
Help help help help he
This isth epla inte xt
To encrypt the message we need to find the intersection between the keyword in plaintext
in the table for example for plain text “t” and keyword “h” the intersection is “a” and for
letter “h” keyword “e” the cipher text is “l” after finished the process we are going to have
the following result .
Keyword : Help help help help he
Plain text : This isth epla inte xt
Ciphertext: alth pxew lswp pret ex
Decryption
For the decryption we use the same table , keyword and our ciphertext , the only difference
is we do not take the intersection between the keyword and plain text but we need to find
the intersection between the keyword and the ciphertext from the given table . for example
if we want to find the intersection between keyword “h” and ciphertext “a” and its “t” we
do continue the process until we get the result .
By : Jawid Arabzada (IIUM)
1.2.2 Autokey Cipher
The problem with the Vigenere cipher was repetition of the key and it can give a very
good opportunity to attackers to find the repetition and decipher the cipher text.in
Autokey cipher the keyword is used only once and we use the plaintext for the
remaining letters of the plaintext as a key.
This idea was published in 1550, by Girolamo Cardano a physician and
mathematician just to avoid the weaknesses that we had in Vigenere cipher keyword
repeat itself. Let’s give an example using the auto key cipher. For the encryption and
decryption of this cipher we still use the standard Vigenere table. For example the
keyword is “alice” and the plaintext is” I hope this works better than...” we will have,
Keyword : a l i c e i h o p e t h i s w o r k s b e t t e …….
Plaintext: i h o p e t h i s w o r k s b e t t e r t h a n..
Ciphertext: I s w r I b o w h a h y s k x s k d w s x a t r
While this Autokey seems to be a good cipher system to replace the Vigenere
but it has a major downside. If the sender mistakenly records a wrong ciphertext
everything is going to be unreadable to the receiver.
Decryption
Decryption of the Autokey cipher is exactly like Vigenere cipher that we have already
discussed about the only difference is the repetition of the key that we use plain text
for the remaining letters in Autokey method.
Before applying these rules as mentioned, the plaintext has to be pre-processed to remove
the letter “j” and any double letters. This is done by replacing all “j” with “I” and placing a
filter letter (usually “x” or “q”) between the repeated letters.
Let’s solve an example; we want to encrypt the text “this text is encrypted using playfair”
with the cryptography.
First we filter the key and remove the repeated letter.
CRYPTOGAHY
c r y p t
o g a h b
d e f I k
l m n q s
u v w x z
It is the time to make pair of the plain text as follow:
Plaintext: th is te xt is en cr yp te du si ng pl ay fa ir
Ciphertext: ph kq yk zp kq fn ry pt rk lc qk ma cq fa nf ep
The complexity of this cipher is 26 X 26 = 676 diagram .
Decryption
By : Jawid Arabzada (IIUM)
The process of deciphering is in a way the reverse process for enciphering. Start with
filtering keyword and create the matrix, then filter the ciphertext and do the following
steps.
(y1,y2) = (x1,x2) ( )
K=
K= ( )
By : Jawid Arabzada (IIUM)
For example we want to encrypt the plaintext “july”. We have two elements of
plaintext to encrypt: (9, 20) (j=9, u=20) and (11, 24) (l=11, y=24). We encrypt it as
follow:
Then we write the equivalent letter to the numbers we got 3 =d 4=e 11=l and 22 = w
so our cipher text is “DELW”.
Decryption
For the decryption first we need to computer the inverse of the Key.
( )-1 = adj = ( )
We need to add 26 to the negative values to get a number between 0 and 25 , and
we get .
( )-1 = ( )
Our cipher text was DELW, (D,E = 3,4) and (L,W = 11,22)
(3,4) ( ) = (9 ,20 )
(9, 20, 11, 24) = july and it was our plain text.
1.3.4 Summary
In short the polygraphic cipher is a cipher in which two or more characters are
enciphered at a time. The result it a cipher that is resistant to single frequency
analysis as well as introducing other problems for the cryptanalysis. However , the
cipher is not secure enough and can be attacked easily using known-plain text
attack .
2 - Transposition Cipher:
in transposition cipher does not substitute the letter to another letter or symbols
instead of it changes the position of the letters , in transposition cipher each letter
preserve its identity but changes its location . The goal of the developer of such a
cipher is to come up with a way in which the pieces can be put in order easily if you
know the key.
By : Jawid Arabzada (IIUM)
2.1 Permutation Cipher
Christensen says, a simple implementation of a transposition cipher is called
permutation cipher. This is much like shuffling a deck of cards in order to randomize
the deal. In this case the plaintext is divided into blocks of some fixed length d and a
permutation function f of the integers 1 to d is selected (2005).
Consider the following plaintext message.
Monoalphabetic unilateral substitution system
We will encipher it using a permutation that divides the message into 5-letter blocks,
monoa lphab eticu nilat erals ubsti tutio nsyst em
Because the numbers of the letters in the plaintext message is not a multiple of 5,
the last block must be padded
monoa lphab eticu nilat erals ubsti tutio nsyst emxxx
Then we rearrange the letters of the blocks according to the following permutation:
1 2 3 4 5
4 5 1 3 2
So for our first five letter
m o n o a
1 2 3 4 5
Becomes
o a m n o
4 5 1 3 2
After finishing the process for all the blocks we will have :
Plaintext : monoa lphab eticu nilat erals ubsti tutio nsyst emxxx
Ciphertext: oamno ablhp cueit atnli lsear tiusb onttu stnys xxexm
Decryption
For decrypting of permutation cipher we simply use the key for example the
ciphertext of first block of our previous example was “ oamno “ and the key is 4 5 1 3
2.
o a m n o
4 5 1 3 2
By : Jawid Arabzada (IIUM)
Simply we can see that the first letter “ o “ postion is the 4th and “a” is the 5th and
“m” is 1 so we rewrite it .
Plaintext : Monoa
Starting with the column headed by "C", our ciphertext begins "DTTFS" from
this column. We now move to the column headed by "O", and move in alphabetical
order.
our ciphertext is “ dttfsdsoaxeeleeehwttnalcxfeahl “
Decryption
Firstly write out the keyword, and then find the length of rows divide the ciphertext
length to the number of key words . for our example the length of the ciphertext is
30 / 6 = 5 it means we have five rows
By : Jawid Arabzada (IIUM)
Next we start filling the matrix in alphabetical order starting from “c” until to the last
one .
our ciphertext is “ dttfsd soaxee leeeh wttnal cxfeahl “
we fill the column in alphabetical order starting from “c” to “y “ . the keyword start
with letter “c” so we start with “c” After the first column is written we can continue
to the end and we will get the result .
1 4 6 3 5 2
C R Y P T O
d e f e n d
t h e e a s
t w a l l o
f t h e c a
s t l e x x
2.4 Summary
In this part we have seen different approach to encryption the transposition cipher.
Instead of substituting one letter or group of letters for another this approach
rearranges the letters in the plaintext. The key to this type of cipher is usually a
geometric figue. The plaintext is written into the figure in one order and read out in
a different order.
By : Jawid Arabzada (IIUM)
References
Mao .(2003). Modern Cryptography: Theory and Practice. New Jersey ,US: Prentice Hall
PTR .
http://crypto.interactive-maths.com/columnar-transposition-
cipher.html
http://practicalcryptography.com/ciphers/columnar-transposition-
cipher/