0% found this document useful (0 votes)
68 views

Cryptography Module 1part 2

Uploaded by

Asmi Tanzaen H N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

Cryptography Module 1part 2

Uploaded by

Asmi Tanzaen H N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 162

CSE3078 – Cryptography and Network Security

School of Computer Science and Engineering and Information Science


Module 1
Introduction to Cryptography and
types of Ciphers

2
Module 1: Introduction to Cryptography and types of
Ciphers

Introduction to Cryptography, Model of Network Security, OSI Security architecture, Security


Attacks: active attacks, passive attacks, services: Authentication, Access Control, Data
Confidentiality, Data Integrity, Nonrepudiation, Substitution Ciphers : Caesar,
Monoalphabetic, Polyalphabetic, Play-fair and Hill Cipher, Introduction to Block Cipher and
Stream Cipher, Feistel Structure

3
Topic 5: Substitution Ciphers

Objective 5.1: Define substitution ciphers and their role in historical cryptography.

Objective 5.2: Describe the Caesar cipher and its encryption/decryption process.

Objective 5.3: Compare and contrast monoalphabetic and polyalphabetic


substitution ciphers.

Objective 5.4: Explain the concepts of Playfair and Hill ciphers and their strengths
and weaknesses.

4
Classification of Cryptosystems
Type of Operations used for  Substitution
transforming plaintext to
ciphertext  Transposition

 Symmetric
The number of keys used
 Asymmetric

The way in which plaintext  Block


is processed  Stream

The Classical vs Modern  Classical algorithms


Ciphers  Modern Cryptography
Classification of Cryptosystems
1. Based on the type of operations used for transforming plaintext to ciphertext
 Substitution: each element in the plaintext (bit, letter, group of bits or
letters) is mapped into another element.

 Transposition: elements in the plaintext are rearranged.


The number of keys used
Substitution Cipher tool
The number of keys used
Classification of Cryptosystems
Classification ofused
The number of keys Cryptosystems
Classification of Cryptosystems
The number of keys used
2. The number of keys used

 Symmetric, single-key, secret-key,  Asymmetric, two-key, or public-


or conventional encryption key encryption

10
Classification of Cryptosystems – Based on Keys
Classification of Cryptosystems – Based on Keys
Classification of Cryptosystems
3. The way in which the plaintext is processed
 Block cipher processes the input one block of elements at a time, producing an output block
for each input block

Plaintext Ciphertext
 Stream cipher processes the input elements continuously, producing output one element at a
time, as it goes along.
Classification of Cryptosystems – Processing of Plaintext

Block cipher
Classification of Cryptosystems – Processing of Plaintext
Classification of Cryptosystems
4. The Classical vs Modern ciphers
 Classical algorithms – those were invented pre-computer up until around the
1950's.
 schemes were designed in an ad-hoc manner and then evaluated based on
their perceived complexity/cleverness
 true ‘strength’ of these schemes was in ‘secrecy’ of their respective
protocols/methods.
Classification of Cryptosystems
4. The Classical vs Modern ciphers

 Modern cryptography – based on scientific foundations


 The strength is NOT in secrecy of protocols but in sound mathematical and
computational principles.
 used for more than just data confidentiality, can protect data integrity, enable
user authentication, etc.
Classification of Cryptosystems
5. Future Trends
Classification of Cryptosystems
Timeline of quantum cryptography
Classification of Cryptosystems
Quantum Cryptography

 Quantum cryptography uses


photons (particles/waves of light)
to transmit a key

 A photon’s spin represents one


piece of information -usually a 1
or a 0, for binary code
Classification of Cryptosystems
Quantum Cryptography
Measures of Security
Unconditionally secure
 An encryption scheme is unconditionally secure if the cipher text
generated by the scheme does not contain enough information to
determine uniquely the corresponding plaintext no matter how
much of cipher text is available.
 With the exception of one-time pad, there is no encryption
algorithm that is unconditionally secure.
Measures of Security

Computationally secure
 Given the best computing devices, the cipher cannot be broken.
 Therefore, what the users of an encryption algorithm can strive for is an
algorithm that meets one or both of the following criteria:
 The cost of breaking the cipher exceeds the value of the
encrypted information.
 The time required to break the cipher exceeds the useful lifetime
of the information.
Classification of Cryptosystems
Substitution Ciphers
A simple substitution cipher, or monoalphabetic cipher, is one in
which each character of the plaintext is replaced with a
corresponding character of cipher text. The cryptograms in
newspapers are simple substitution ciphers.
Substitution Ciphers
 Monoalphabetic substitution:
 Each character of the plaintext is replaced with a
corresponding character of cipher text.
 The cryptograms in newspapers are simple substitution ciphers.
Example: Caesar Cipher

 Polyalphabetic substitution:
 Cipher is made up of multiple monoalphabetic
substitutions.
Example: Vigenère Cipher
Simple • Caesar Cipher.
Substitution • Pigpen Cipher
Cipher, or • ROT13 Cipher.
Mono- • Atbash Cipher.
alphabetic • Affine Cipher.
Cipher
Classical Substitution - Caesar Cipher
 Earliest and simplest was by Julius Caesar.
 Primarily used in warfare.
 Involves replacing each letter of the alphabet with the letter standing three
places further down the alphabet.
 This cipher replaces each letter by nth letter down the alphabet.
Example:
Plain text:
MEET ME AFTER THE PARTY
Cipher text:
PHHW PH DIWHU WKH SDUWB
Classical Substitution - Caesar Cipher - Mathematically
How it works?
 Alphabet is wrapped around ,so that the letter following Z is A.
 Assign a numerical equivalent to each letter as follows :
A=0
B=1
C=2
Z = 25
 For each plaintext letter P, substitute for cipher text C as :
C = (P + 3) mod 26
 A shift may be of any amount, so that in general Caesar algorithm is:
C = (P + K ) mod 26 where k is any value from 1 to 25.
 The decryption algorithm is given by:
P = (C - K) mod 26
https://crypto.interactive-maths.com/caesar-shift-cipher.html
Classical Substitution –
Pigpen Cipher
 Example of a substitution
cipher
 The letters are replaced by
symbols.
 Freemasons, a secret
society in the 18th
Century.
Classical Substitution - Pigpen Cipher

message : X MARKS THE SPOT


Classical Substitution - ROT-13 Cipher
ROT13 ("rotate by 13 places", usually hyphenated ROT-13)
ROT-13 is a simple encryption cipher. It is a variant of the Caesar Cipher.
Encryption Method: C = P + K Key Always = 13
Decryption Method: P = C - K Key Always = 13
Classical Substitution - ROT-13 Cipher

Encode the following Plaintext

Plaint Text : ATTACK AT DAWN


Cipher Text : NGGNPX NG QNJA
Classical Substitution - Atbash Cipher
 Atbash is a simple substitution cipher for the Hebrew alphabet. Using this
method
 sometimes the encrypted words has another meaning.
Encryption Method: Reversing each letter once.
Decryption Method: Reversing each letter once.
Classical Substitution - Atbash Cipher

Encode the following Plaintext

Plaint Text : B E P R E P A R E D F O R T H E A T T A C K
Cipher Text : Y V K I V K Z I V W U L I G S V Z G G Z X P
Modulo Arithmetic
Example #1
What is 16 mod 12?
16 divided by 12 equals 1 remainder 4. So the answer is 4!

Example #2
What about 15 mod 2?
15 divided by 2 equals 7 remainder 1, so the solution is 1!

Example #3
And if you have 18 mod 9?
18 divided by 9 equals 2 remainder 0, so that means 18 mod 9 is equivalent to
0!
Modulo Arithmetic

Evaluate -97 mod 11.


-97 divided by 11 equals -8 remainder -9.

-n mod k = k-(n mod k)


-97 mod 11 = 11 – (97 mod 11)
= 11 – (equals 8 remainder 9) = 11 – 9 = 2

-60 mod 26 = 26 – (60 mod 26) = 26 – (equals 2 remainder 8) = 26 – 8 = 18


Classical Substitution - Affine Cipher
 In Affine Cipher each letter in an alphabet is mapped to its numeric
equivalent as English alphabet is 26 character therefore ( m = 26 ).

Encryption Method : E(x) = ( ax + b) mod m


Decryption Method : D(x) = c(x-b) mod m
 a * c = 1 mod 26 …Find the inverse of a
 the inverse of 5 modulo 26 is 21,
 i.e. 5*21 = 1 (mod 26).
43 mod 600. Find the inverse. a . a-1 = 1 mod m; Technically
43 ⋅ a-1 ≡ 1 mod 600 gcd(a,m) = 1
1. Euclidian Algorithm 3. Back Tracking and Applying 4. Solving for
600 = 13(43) + 41 Extended Euclidian Algorithm negative modulo
43 = 1(41) + 2 1= 1(41) – 20(43 – 1(41)) -293 mod 600
41 = 20(2) + 1 1= 1(41) – 20(43) + 20(41) = 600–293 mod 600
(Stop when getting 1= 21(41) – 20(43) = 307
remainder as 1) 1= 21(600 – 13(43)) – 20(43)
1= 21(600) – 273(43) – 20(43) 43 * 307 = 13201
2. Equating these,
1=21(600) – 293(43) and
41 = 600 – 13(43)
13201 = 1 mod 600
2 = 43 - 1(41)
It negative,
1 = 41 - 20(2)
So a-1 = 307
20 mod 97. Find the inverse. a . a-1 = 1 mod m; Technically
20 ⋅ a-1 ≡ 1 mod 97 gcd(a,m) = 1
1. Euclidian Algorithm 3. Back Tracking and Applying So
97 = 4(20) + 17 Extended Euclidian Algorithm 20 * 34 = 680
20 = 1(17) + 3 1 = 1(3) – 1(2) and
17 = 5(3) + 2 1 = 1(3) – 1(17 – 5(3)) 680 = 1 mod 97
3 = 1(2) + 1 1 = 1(3) – 1(17) + 5(3)
(Stop when getting remainder as 1) 1 = 6(3) – 1(17) So a-1 = 34
2. Equating these,
1 = 6(20 – 1(17)) – 1(17)
1 = 3 - 1(2) 1 = 6(20) – 6(17) – 1(17)
2 = 17 – 5(3) 1 = 6(20) – 7(17)
3 = 20 – 1(17) 1 = 6(20) – 7(97 – 4(20)
17 = 97 – 4(20) 1 = 6(20) – 7(97) + 28(20)
1 = 34(20) – 7(97)
Classical Substitution - Affine Cipher

Encryption Encryption Key : a = 5, b = 8


Plain Text A F F I N E C I P H E R
x 0 5 5 8 13 4 2 8 15 7 4 17
ax+b 5x+8 8 33 33 48 73 28 18 48 83 43 28 93
ax+b mod 26 5x+8 mod 26 8 7 7 22 21 2 18 22 5 17 2 15
Cipher Text I H H W V C S W F R C P

Decryption Ciphertext I H H W V C S W F R C P
y 8 7 7 22 21 2 18 22 5 17 2 15
-1
a (y-b) 21(y − 8) 0 -21 -21 294 273 -126 210 294 -63 189 -126 147
-1
a (y-b) mod 26 21(y − 8) mod 26 0 5 5 8 13 4 2 8 15 7 4 17
Plaintext A F F I N E C I P H E R
Classical Substitution - Affine Cipher
Practical Activity
Assume we discard all non alphabetical characters including
spaces.
Let the key be a=5 and b= 7.
The encryption function is then (5*p + 7)(mod 26).
Encode: defend the east wall of the castle
Cipher Text :
wbgbuw yqb bhty nhkk zg yqb rhtykb
Classical Substitution - Homophonic Cipher
 A homophonic substitution cipher is like a simple substitution
cryptosystem, except a single character of plaintext can map to one of
several characters of ciphertext. For example, "A" could correspond to
either 5, 13, 25 or 56, "B" could correspond to either 7,19,31,or 42,
and so on.
A Mantua Homophonic Cipher (15th century, Roman Empire) is an example to this type of cipher.

The cipher text alphabet when the key phrase "18 fresh tomatoes and 29 cucumbers" is used
with the alpha-numeric alphabet, assigning multiple symbols to the most common letters.
Classical Substitution - Homophonic Cipher
https://asecuritysite.com/coding/ho
 Vigenère Cipher
Polyalphabetic  Beaufort Cipher
Substitution  One Time Pad Cipher
cipher  Vernam Cipher
 Playfair Cipher
Polyalphabetic Substitution - Vigenère Cipher
Vigenere Cipher
• Simplest polyalphabetic substitution cipher
• Effectively multiple Caesar cipher
• Proposed by Blaise de Vigenère from the court of Henry III of
France in the sixteenth century, is a polyalphabetic substitution based
on the Vigenère table
• Uses below Vigenère table together with a keyword to encipher
plaintext
Vigenère
Cipher –
Vigenère
Table
Vigenère Cipher
 Example:

 A key is needed that is as long as the message


 The key is a repeating keyword.
Vigenère Cipher
Encryption
 Choose a keyword (or keyphrase).
 Repeat this keyword over and over until it is
the same length as the plaintext. This is called
the keystream.
 The keystream b means we choose the row
with B at the top, and the plaintext "a" means
we choose the column with A at the left. We
get the ciphertext "B".
 For the second plaintext letter "s", we go
down to S on the top, and use the
keystream a to go to A along the left. We get
the ciphertext letter "
S".
Vigenère Cipher
Decryption
We look along the top row to find the letter from
the keystream, G. We look down this column
(in yellow) and find the ciphertext letter "Z"
(in green). We then go along this row (in blue)
to the left hand edge, and the letter here
(in purple) is the plaintext letter. In this case it is
"t".

In the same way as above, we find


the keystream letter I, and find the ciphertext
letter "P" in this column. We then follow
this row to find the plaintext letter "h".
Vigenère Cipher
plaintext = MICHIGAN TECHNOLOGICAL UNIVERSITY
Keyword = HOUGHTON.

Plain text : MICHIGAN TECHNOLOGICAL UNIVERSITY


Key : HOUGHTON HOUGHTONHOUGH TONHOUGNTO

Dividing the result into 5-letter blocks. As a result, the above plaintext and
keyword become the following:

MICHI GANTE CHNOL OGICA LUNIV ERSIT Y


HOUGH TONHO UGHTO NHOUG HTONH OUGHT O
Beaufort Cipher
 The Beaufort cipher, created by Sir Francis Beaufort, is a polyalphabetic
substitution cipher that is similar to the Vigenère cipher, except that it enciphers
characters in a slightly different manner.
 The difference is in how the Tabula Recta is used to get to the ciphertext letter.
 The process is reversed.
 It is cipher is a reciprocal cipher, that is, decryption and encryption algorithms
are the same.
 Due to the symmetric nature of the Tabula Recta, decrypting the Beaufort
Cipher uses an identical method to the encryption process.
Beaufort Cipher
Algorithm
Encipher:
Encode a letter with a Beaufort cipher you find the letter in the top row.
Trace down until you find the key letter.
Trace over to the left most column to find the enciphered letter.

Decipher:
Decipher a letter, you find the letter (plaintext) in the left column,
Trace over to the key letter
Trace up to find the deciphered letter.
Beaufort Cipher
Encryption
if we want to encrypt the plaintext letter
“D" with the keystream letter ”M”, then
we:
Find the column with “D" at the top
(yellow column)
Going down this column we identify the
keystream letter ”M” (green box)
Go to the far left of this row (blue row)
Take the letter "J" as the ciphertext
letter (purple box)
Cipher
Decryption
if we want to decrypt
Take the letter "J" as the ciphertext letter
(purple box)
Go to the far left of this row (blue row)
Going down this row we identify the
keystream letter m (green box)
Find the column with "d" at the top
(yellow column) keystream letter m,
then we: the plaintext letter "d"
Beaufort Cipher
 Assume we are enciphering the plaintext letter D with the key letter F
 Now we take the letter we will be encoding, and find the column on the
tableau, in this case the 'D' column.
 Then, we move down the 'D' column of the tableau until we come to the key
letter, in this case 'F' (The 'F' is the keyword letter for the first 'D').
 Our ciphertext character is then read from the far left of the row our key
character was in, i.e. with 'D' plaintext and 'F' key, our ciphertext character is
'C'.
 So, the ciphertext for the above plaintext is: D > F > C
Beaufort Cipher
Practical Activity :
encipher a message, repeat the keyword above the plaintext:

Keyword : FORTIFICATIONFORTIFICATIONFO

Plain Text : DEFENDTHEEASTWALLOFTHECASTLE

Cipher Text : CKMPVCPVWPIWUJOGIUAPVWRIWUUK


One Time Pad (OTP)
Cipher
 Key or pad is if the plain text and used
only once.
 If key is truly random, kept secret, never
reused, then One Time Pad is unbreakable.
 Truly unconditionally secure.
 One time use is mandatory.
 Key is shared in One Time Pad
One Time Pad (OTP)
Cipher
 The only theoretically unbreakable
encryption system
 A list of numbers, in completely random
order that is used to encode a message
 Only used once
 Invented in 1917.
 The Encryption algorithm is a stream
cipher.
 Plaintext is combined with a random
"key" or "pad"
One Time Pad (OTP) Cipher
 Alice sends a message to Bob
 Message or the plain text is - Hello.
 The method used is Modular addition ( Mod 26 )
 Key is randomly generated. (0 to 25)

Applications
 Only for communication between 2 parties.
 Educational value.
 Both parties do most of the work by hand, not using computers, e.g. Espionage
One Time Pad (OTP) Cipher
Draw Back of One Time Pad
 No mechanism in One Time Pad to provide message integrity
 It is susceptible to man in the middle attack.
 Transporting One Time Pad key (CD's, floppies, etc.,) is
vulnerable.
 Can use AES, PKC etc.
One Time Pad (OTP) Cipher

One Time Pad (OTP)


Ke y X M C K L
Ke y Value 23 12 2 10 11
Plain Te xt H E L L O
Plain Te xt Value 7 4 11 11 14
(Ke y + Plain) mod 26 4 16 13 21 25
Ciphe rte xt E Q N V Z
Ke y X M C K L
Ke y Value 23 12 2 10 11
(Ciphe r Te xt - Ke y) - 19 4 11 11 14
(Ciphe r Te xt - Ke y) mod 26 7 4 11 11 14
Plainte xt H E L L O
One Time Pad (OTP) Cipher
OTP Implementation with Binary Data
 The idea of a one-time pad can be easily extended to binary data.
 Instead of a one-time pad consisting of characters, use a one-time pad
of bits.
 To encrypt, XOR each bit of plaintext with each bit of key
 To decrypt, XOR each bit of cipher text with each bit of same key
 Everything else remains the same and the security is just as perfect.
One Time Pad (OTP) Cipher - Security
 The security of the one-time pad is randomness of the key.
 Stream of characters (or numbers) that constitute the key is truly
random, then the stream of characters that constitute the cipher text
will be truly random. Thus, there are no patterns or regularities that
a cryptanalyst can use to attack the cipher text.
 In theory, the one-time pad offers complete security but, in practice it
has two fundamental difficulties:
 Generation of large number of truly random pads(keys).
 Key distribution and protection.
 Because of these difficulties, the one-time pad is of limited utility,
and is useful only for short messages, in very high-security
One Time Pad (OTP) Cipher - Security
 In theory, the one-time pad offers complete security but, in practice it
has two fundamental difficulties:
 Generation of large number of truly random pads(keys).
 Key distribution and protection.
 Because of these difficulties, the one-time pad is of limited utility,
and is useful only for short messages, in very high-security
environments.
Vernam Cipher - Digital bit-wise XOR
 The Vernam Cipher is based on the principle that each plaintext character from
a message is 'mixed' with one character from a key stream.
 If a truly random key stream is used, the result will be a truly
'random' ciphertext which bears no relation to the original plaintext.
 In that case the cipher is similar to the unbreakable One-Time Pad (OTP).
 As it was generally used with teleprinters and 5-level punched tape, the system
is also known as One-Time Tape or OTT.
Vernam Cipher - Digital bit-wise XOR
Vernam Cipher - Digital bit-wise XOR
 The ciphertext is generated by applying the logical XOR operation (exclusive-or) to the
individual bits of plaintext and the key stream. The advantage of using the XOR operation for
this, is that it can be reverted, simply by carrying out the same operation again. In other
words:
Vernam Cipher - Digital bit-wise XOR
Vernam Cipher - Digital bit-wise XOR
Vernam Cipher
Plain Te xt E l v i s
69 108 118 105 115
Ke y © Ï Ã † ¬
169 207 195 134 172
Plain Te xt 01000101 01101100 01110110 01101001 01110011
Ke y 10101001 11001111 11000011 10000110 10101100
XOR(Plain Te xt, Ke y) 11101100 10100011 10110101 11101111 11011111
236 163 181 239 223
Ciphe rte xt ì £ µ ï ß
01000101 01101100 01110110 01101001 01110011
69 108 118 105 115
Plainte xt E l v i s
 First described by Charles Wheatstone in 1854
 Named after Lord Playfair, who heavily promoted it in
military
 It’s a block substitution cipher or Digraph Substitution
Cipher
 The best-known multiple-letter encryption cipher
Playfair  Encrypts and Decrypts 2 blocks of character (diagraph) at a
Cipher time
 Digraphs the plaintext as single units and translates these
units into cipher text digraphs.
 is based on the use of a 5 X 5 matrix of letters constructed
using a keyword. The keyword is agreed upon by both sender
and receiver
Playfair Cipher - Encryption
Encrypt Agree Draw

Encrypt the plaintext Agree upon a keyword : Draw a 5 X 5 matrix (Polybius


"hide the gold in the Square) without heading, since 25
‘PLAYFAIR alphabets can fit , combine I & J and
tree stump" EXAMPLE’ represent as I

 Starting with the letters of the keyphrase,


and ignoring any letters we already have in
the square. We are also going to combine
"I" and "J" in the square.
Playfair Cipher - Encryption
Split the plaintext up into digraphs (that is pairs of letters).

Plain
Text HI DE TH EG OL DI NT HE TR EE ST UM P

Plain
Text HI DE TH EG OL DI NT HE TR EQ ES TU MP
Split the plaintext up into digraphs (that is pairs of letters). On each
digraph we perform the following encryption steps:

Rule 1:
Playf If the digraph consists of the same letter twice (or there is only one
air
letter left by itself at the end of the plaintext) then insert the letter "X"
Ciphe
r between the same letters (or at the end), and then continue with the rest
Encry of the steps.
ption Rule 2:
Steps
If the two letters appear on the same row in the square, then replace each
letter by the letter immediately to the right (during encryption) or to the
left (during decryption) of it in the square (cycling round to the left hand
side if necessary).
Rule 3:
If the two letters appear in the same column in the square, then replace
each letter by the letter immediately below them (during encryption) or
above them (during decryption) it in the square (cycling round to the top
Playfa of the square if necessary).
ir
Ciphe
r
Encry Rule 4:
ption
Otherwise, form the rectangle for which the two plaintext letters are two
Steps
opposite corners. Then replace each plaintext letter with the letter that
forms the other corner of the rectangle that lies on the same row as that
plaintext letter (being careful to maintain the order).
The ciphertext digraphs

We can now write out the ciphertext as a long string


"BMODZBXDNABEKUDMUIXMMOUVIF" or split it into block of 5 "BMODZ BXDNA
BEKUD MUIXM MOUVI F" or even give it the same layout as the original "BMOD ZBX
DNAB EK UDM UIXMM OUVIF"
Playfair Cipher - Encryption
Message : P L A Y F
HIDE THE GOLD IN THE TREE STUMP
Key : PLAYFAIR EXAMPLE I R E X M
Pad : Q B C D G H
Formatted Message :
HIDETHEGOLDINTHETREQESTUMP K N O Q S
Encrypted Message :
T U V W Z
BMODZBXDNABEKUDMUIXOMOUVIF
Plain
Text HI DE TH EG OL DI NT HE TR EQ ES TU MP

Rule 4 3 4 4 4 4 4 4 4 4 4 2 4
Cipher
Text BM OD ZB XD NA BE KU DM UI XO MO UV IF
Playfair Cipher - Decryption
Message : P L A Y F
HIDE THE GOLD IN THE TREE STUMP
Key : PLAYFAIR EXAMPLE I R E X M
Pad : Q B C D G H
Formatted Message :
HIDETHEGOLDINTHETREQESTUMP K N O Q S
Encrypted Message :
BMODZBXDNABEKUDMUIXOMOUVIF T U V W Z
Cipher
Text BM OD ZB XD NA BE KU DM UI XO MO UV IF
Rule 4 3 4 4 4 4 4 4 4 4 4 2 4
Plain
Text HI DE TH EG OL DI NT HE TR EQ ES TU MP
Playfair Cipher - Encryption
P U Z L E
Message : NETWORKSECURITY A B C D F
Key : PUZZLE
Pad : Q G H I K M
Formatted Message : NETWORKSECURITYQ N O Q R S
Encrypted Message : SPVXQSMRZFLOGWWS
T V W X Y

Plain Text NE TW OR KS EC UR IT YQ

Rule 4 2 2 4 4 4 4 4

Cipher Text SP YX QS MR ZF LO GW WS
Playfair Cipher - Decryption
P U Z L E
Message : NETWORKSECURITY
A B C D F
Key : PUZZLE
Pad : Q G H I K M
Formatted Message : NETWORKSECURITYQ N O Q R S
Encrypted Message : SPVXQSMRZFLOGWWS
T V W X Y

Cipher Text SP VX QS MR ZF LO GW WS
Rule 4 2 2 4 4 4 4 4
Plain Text NE TW OR KS EC UR IT YQ
Playfair Cipher

Playfair Cipher [2]


• Example
• Keyword: MONARCHY
Playfair Cipher
 Security
 Playfair cipher can be easily cracked if there is enough text.
 Obtaining the key is relatively straightforward if both plaintext
and ciphertext are known.
 When only the ciphertext is known, brute force cryptanalysis
of the cipher involves searching through the key space for
matches between the frequency of occurrence of digraphs
(pairs of letters) and the known frequency of occurrence of
digraphs in the assumed language of the original message.
Playfair Cipher
 Security
Playfair digraph and its reverse (e.g. AB and BA) will decrypt to
the same letter pattern in the plaintext (e.g. RE and ER). In English,
there are many words which contain these reversed digraphs such
as REceivER and DEpartED.
Hill Cipher
 Created by Lester S. Hill in 1929
 Polygraphic Substitution Cipher
 Uses Linear Algebra to Encrypt and Decrypt
Hill Cipher
 Hill Cipher was invented and developed in 1929 by Lester S. Hill.
 The Hill cipher is an example of a block cipher.
 A block cipher is a cipher in which groups of letters are enciphered together in
equal length blocks .
 The Hill cipher is a polygraphic substitution cipher built on concepts from
Linear Algebra.
 Key is represented in form of matrix (2 x2 or 3x3 , etc..)
(Note: Determinate of Key matrix must be non-zero)
 Each letter is represented by number 0 to 25 and calculation are based on mod 26.
 The Hill cipher makes use of modulo arithmetic, matrix multiplication, and
matrix inverses; hence, it is a more mathematical cipher than others
Hill Cipher - Encryption
 Encrypting with the Hill cipher is built on the following operation:
C = (K*P) mod 26
 Where K is our key matrix and P is the plaintext in vector form.
 Matrix multiplying these two terms produces the encrypted ciphertext.

Example: Key= HILL


Plaintext=exam
Key Matrix=

Plain Text =
Hill Cipher – Encryption
Example-2
 Encrypting with the Hill cipher is built on the following operation:
C = (K*P) mod 26
 Where K is our key matrix and P is the plaintext in vector form.
 Matrix multiplying these two terms produces the encrypted ciphertext.

Example:
Key= HILL Key Matrix=
Plaintext=short example

Plain Text:

=
Hill Cipher – Encryption
Example-2

How to find 275 mod 26?


=275/26
=10.5769
10.5769-10
0.5769x26=15
ciphertext = "APADJ TFTWLFJ".
Hill Cipher – Encryption
Example-2

ciphertext = "APADJ TFTWLFJ".


Hill Cipher – Encryption
Example-3
Example:
Key= CDDG
Plaintext=ATTACK
Hill Cipher – Encryption
Example-3
Hill Cipher – Encryption
Example-3
Hill Cipher – Encryption
Example-3
Hill Cipher – Encryption
 Encrypting with the Hill cipher is built on the following operation:
C = (K*P) mod 26
 Where K is our key matrix and P is the plaintext in vector form.
 Matrix multiplying these two terms produces the encrypted ciphertext.
Example:
Key= BKAAUBCPC
Plaintext= retreat now
Hill Cipher
Encryption

C= P*K mod 26
Hill Cipher
Encryption

C= P*K mod 26
Hill Cipher
Encryption

C= P*K mod 26
Hill Cipher
Encryption

C= P*K mod 26
Hill Cipher
Decryption

P= C-1*K mod 26
Hill Cipher
Decryption
P= C-1*K mod 26

Step 1: Calculate the multiplicative inverse for the determinant.


Step 2: Multiply it with Adjoint matrix
Step 3: Multiple inverse key matrix with Cipher text matrix to obtain
plaintext
Hill Cipher – Decryption: Example 2x2 Key matrix
Step 1: Calculate the multiplicative inverse for the determinant.

1.1 Find Determinate of the Matrix

Key Matrix =

D=15
Hill Cipher – Decryption: Example 2x2 Key matrix
Step 2: Calculate the multiplicative inverse for the determinant.
1.2 Find multiplicative inverse of Determinate of the Matrix

dd-1
 1 mod 26

d * d-1 mod 26 =1

= 15 * d-1 mod 26 =1 (Hit and trial Method)

If d-1 = 7 then 15*7 mod 26 = 105 mod 26 = 1


hence d-1 =7
Hill Cipher – Decryption: Example 2x2 Key matrix
Step 2: Multiply multiplicative inverse of the determinant with adjoint matrix
2.1 Calculate Adjoint matrix

And for negative values, we have to add them with 26 to get the desired values between 0 and 25
for use in the decryption formula.
Hill Cipher – Decryption: Example 2x2 Key matrix
Step 2: Multiply multiplicative inverse of the determinant with adjoint matrix
2.2 Multiply d-1 with Adjoin matrix
Hill Cipher – Decryption: Example 2x2 Key matrix
Step 3: Multiply inverse key matrix with Cipher text matrix to obtain plaintext
ciphertext as
‘ELSC’
Hill Cipher Decryption: Example 2
Key: HILL

Ciphertext: APADJ TFTWLFJ

Step 1: Calculate the multiplicative inverse for the determinant.


Step 2: Multiply it with Adjoin matrix
Step 3: Multiple inverse key matrix with Cipher text matrix to obtain
plaintext
Hill Cipher – Decryption: Example 2x2 Key matrix
Step 1: Calculate the multiplicative inverse for the determinant.

1.1 Find Determinate of the Matrix

Key Matrix =

D=15
Hill Cipher – Decryption: Example 2x2 Key matrix
Step 2: Calculate the multiplicative inverse for the determinant.
1.2 Find multiplicative inverse of Determinate of the Matrix

dd-1
 1 mod 26

d * d-1 mod 26 =1

= 15 * d-1 mod 26 =1 (Hit and trial Method)

If d-1 = 7 then 15*7 mod 26 = 105 mod 26 = 1


hence d-1 =7
Hill Cipher – Decryption: Example 2x2 Key matrix
Step 2: Multiply multiplicative inverse of the determinant with adjoint matrix
2.1 Calculate Adjoint matrix

And for negative values, we have to add them with 26 to get the desired values between 0 and 25
for use in the decryption formula.
Hill Cipher – Decryption: Example 2x2 Key matrix
Step 2: Multiply multiplicative inverse of the determinant with adjoint matrix
2.2 Multiply d-1 with Adjoin matrix
Hill Cipher – Decryption: Example 2x2 Key matrix
Step 3: Multiple inverse key matrix with Cipher text matrix to obtain plaintext
ciphertext as ‘APADJ TFTWLFJ’
Hill Cipher – Decryption: Example 2x2 Key matrix
Step 3: Multiple inverse key matrix with Cipher text matrix to obtain plaintext
ciphertext as ‘APADJ TFTWLFJ’
Hill Cipher – Decryption: Example 2x2 Key matrix
Step 3: Multiple inverse key matrix with Cipher text matrix to obtain plaintext
ciphertext as ‘APADJ TFTWLFJ’
Hill Cipher – Decryption: Example 2x2 Key matrix
Step 3: Multiple inverse key matrix with Cipher text matrix to obtain plaintext
ciphertext as
‘APADJ TFTWLFJ’
Hill Cipher – Decryption: Example 2x2 Key matrix
Step 3: Multiple inverse key matrix with Cipher text matrix to obtain plaintext
ciphertext as
‘APADJ TFTWLFJ’
Hill Cipher – Decryption: Example 2x2 Key matrix
Step 3: Multiple inverse key matrix with Cipher text matrix to obtain plaintext
ciphertext as
‘APADJ TFTWLFJ’
Hill Cipher Decryption: Example 3
Key: CDDG
Ciphertext: FKMFIO

Step 1: Calculate the multiplicative inverse for the determinant.


Step 2: Multiply it with Adjoin matrix
Step 3: Multiple inverse key matrix with Cipher text matrix to obtain plaintext
Hill Cipher Decryption: Example 3
Key: CDDG
Ciphertext: FKMFIO

Step 1: Calculate the multiplicative inverse for the determinant.


Step 2: Multiply it with Adjoin matrix
Step 3: Multiple inverse key matrix with Cipher text matrix to obtain plaintext
Hill Cipher Decryption: Example 3
Step 1: Calculate the multiplicative inverse for the determinant.

1.1 Find Determinate of the Matrix

Key Matrix =

D=3
Hill Cipher Decryption: Example 3
Step 2: Calculate the multiplicative inverse for the determinant.

1.2 Find multiplicative inverse of Determinate of the Matrix

dd-1
 1 mod 26

d * d-1 mod 26 =1

= 3 * d-1 mod 26 =1 (Hit and trial Method)

If d-1 = 9 then 3*9 mod 26 = 27 mod 26=1


hence d-1 =9
Hill Cipher Decryption: Example 3
Step 2: Multiply multiplicative inverse of the determinant with adjoint matrix

2.1 Calculate Adjoint matrix

And for negative values, we have to add them with 26 to get the desired values between 0 and
25 for use in the decryption formula.
Hill Cipher Decryption: Example 3
Step 2: Multiply multiplicative inverse of the determinant with adjoint matrix

2.2 Multiply d-1 with Adjoint matrix


Hill Cipher Decryption: Example 3
Step 3: Multiple inverse key
matrix with Cipher text matrix
to obtain plaintext
ciphertext =
‘FKMFIO’
Hill Cipher Decryption: Example 3
Step 3: Multiple inverse key
matrix with Cipher text matrix
to obtain plaintext
ciphertext = ‘FKMFIO’
Hill Cipher Decryption: Example 3
Step 3: Multiple inverse key
matrix with Cipher text matrix
to obtain plaintext
ciphertext = ‘FKMFIO’
Hill Cipher – Decryption: Example 3x3 Key matrix
Step 1: Calculate the multiplicative inverse for the determinant.
Step 2: Multiply it with Adjoin matrix
Step 3: Multiple inverse key matrix with Cipher text matrix to obtain plaintext

Key: AHELATPBA

Ciphertext: SYICHOLER
Hill Cipher – Decryption: Example 3x3 Key matrix
Step 1: Calculate the multiplicative inverse for the determinant.

1.1 Find Determinate of the Matrix


Hill Cipher – Decryption: Example 3x3 Key matrix
Step 1: Calculate the multiplicative inverse for the determinant.
1.1 Find Determinate of the Matrix
Hill Cipher – Decryption: Example 3x3 Key matrix
Step 2: Calculate the multiplicative inverse for the determinant.
1.2 Find multiplicative inverse of Determinate of the Matrix

 1 mod 26
dd-1

d * d-1 mod 26 =1

= 11 * d-1 mod 26 =1 (Hit and trial Method)

If d-1 = 19 then 11*19 mod 26 = 209 mod 26=1


hence d-1 =19
Hill Cipher – Decryption: Example 3x3 Key matrix
Step 2: Multiply multiplicative inverse of the determinant with adjoin matrix
2.1 Calculate Adjoin matrix (Method 1)
Hill Cipher – Decryption: Example 3x3 Key matrix
Step 2: Multiply multiplicative inverse of the determinant with adjoin matrix

2.1 Calculate Adjoin matrix (Method 2)


First calculate cofactor matrix

Then transpose the cofactor matrix


Hill Cipher – Decryption: Example 3x3 Key matrix
Step 2: Multiply multiplicative
inverse of the determinant with
adjoin matrix
2.1 Calculate Adjoin matrix (Using
Method 1)

And for negative values, we have to


add them with 26 to get the desired
values between 0 and 25 for use in
the decryption formula.
Hill Cipher – Decryption: Example 3x3 Key matrix
Step 2: Multiply multiplicative inverse of the determinant with adjoin matrix

2.2 Multiply d-1 with Adjoin matrix


Hill Cipher – Decryption: Example 3x3 Key matrix
Step 3: Multiple inverse key matrix with Cipher text matrix to obtain plaintext
ciphertext = ‘SYICHOLER’
Hill Cipher – Decryption: Example 3x3 Key matrix
Step 3: Multiple inverse key matrix with Cipher text matrix to obtain plaintext
ciphertext = ‘SYICHOLER’
Cryptanalysis of Hill Cipher
 As with Playfair, the strength of the Hill cipher is that it completely
hides single-letter frequencies. Indeed, with Hill, the use of a larger
matrix hides more frequency information.
 Thus, a 3*3 Hill cipher hides not only single-letter but also two-letter
frequency information
 The Hill Cipher's weaknesses to the known- plaintext attack is
considered as its most important security imperfection since it can
be cracked by taking n distinct pairs of plaintext and corresponding
cipher-text
Other Mono-alphabetic
Substitution Ciphers
Morse Code
One of the most famous examples of
a cipher in regular use is Morse Code
(which is not a code, but rather a
cipher). Morse Code has the benefit
that it can be transmitted in several
ways, such as written, by sound or
by light. Each letter is replaced by a
series of dots and dashes as given by
the key below.
Other Mono-alphabetic
Substitution Ciphers
Other Mono-alphabetic Substitution Ciphers
The Adventure of the Dancing Men
Another example of uses of ciphers is taken not from
history, but popular culture. It comes in the form of a
Sherlock Holmes Story, written by Sir Arthur Conan
Doyle.

In this example, Sherlock Holmes is called in to help


solve a mystery surrounding a piece of paper with
strange stick figures on it. He uses his ingenious to
both crack the code, and to send a message to the
killer using his own code to entice him to come to the
scene, unknowing that the message was written by
Holmes.
An image of a Scytale with 10
Transposition Cipher faces.

A kind of mapping achieved by performing some sort of permutation on the


plaintext letters.
• Rail Fence Technique
– plaintext is written down as a sequence of diagonals and then read off as a
sequence of rows
• Columnar Transposition Cipher
– writes the message in a rectangle, row by row, and read the message off,
column by column, but permute the order of the columns
Rail Fence Cipher.

Transposition Route Cipher.


Cipher Simple Columnar Cipher.

Keyword Columnar Cipher.


Transposition Cipher – Rail fence Cipher

 To encrypt, write the plaintext in a zigzag pattern in two rows and


form the cipher text by reading off the letters from the first row
followed by the second.
 To decrypt, write the cipher text in two rows and read off the plaintext
in a zigzag fashion.
Transposition Cipher - Rail fence Cipher
Example1: Rail fence of depth 2
Plaintext: “meet me after the toga party”
Encryption:
M - E - M - A - T - R - H - T - G - P - R - Y -
- E - T - E - F - E - T - E - O - A - A - T - X
Ciphertext:
M E M AT R H TG P RY E T E F E T EOA AT X

https://crypto.interactive-maths.com/rail-fence-cipher.html
Transposition Cipher - Rail fence Cipher
Example1: Rail fence of depth 3
Plaintext: “meet me after the toga party”
Encryption:
M - - - M - - - T - - - H - - - G - - - R - -
- E - T - E - F - E - T - E - O - A - A - T -
- - E - - - A - - - R - - - T - - - P - - - Y

Ciphertext:
M M T H G R E T E F E T E O A AT E A RT P Y
https://crypto.interactive-maths.com/rail-fence-cipher.html
Transposition Cipher - Rail fence Cipher
Example1: Rail fence of depth 4
Plaintext: “meet me after the toga party”
Encryption:
M - - - - - A - - - - - H - - - - - P - - - - - X - - -
- E - - - E - F - - - T - E - - - A - A - - - X - X - -
- - E - M - - - T - R - - - T - G - - - R - Y - - - X -
- - - T - - - - - E - - - - - O - - - - - T - - - - - X

Ciphertext:
M AHPXEEFTEAAXXEMTRTGRYXTEOTX
https://crypto.interactive-maths.com/rail-fence-cipher.html
Transposition Cipher - Rail fence Cipher
Plain Text : "DEFEND THE EAST WALL", with a key of 3,
D - - - N - - - E - - - T - - - L - -
- E - E - D - H - E - S - W - L - X -
- - F - - - T - - - A - - - A - - - X

 Note that at the end of the message we have inserted two "X"s. These are called nulls,
and act as placeholders.
 Makes 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.
 Its not mandatory, 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".
Rail fence Cipher
Decryption
 Reconstruction is done as a diagonal grid
 Write messages but leaving dash in place spaces
 Replace all dashes with corresponding letters and read off the plaintext
 Ciphertext "TEKOOHRACIRMNREATANFTETYTGHH", encrypted with a key of 4,
 Construct a table with 4 rows because the key is 4, and 28 columns as the ciphertext has length 28.
 Place the "T" in the first square
 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.
T - - - - - E - - - - - K - - - - - O - - - - - O - - -
- H - - - R - A - - - C - I - - - R - M - - - N - R - -
- - E - A - - - T - A - - - N - F - - - T - E - - - T -
- - - Y - - - - - T - - - - - G - - - - - H - - - - - H
Rail fence Cipher

Plain Text : THEY ARE ATTACKING FROM THE


NORTH
Transposition Cipher - Columnar Transposition Cipher
How it works?
 Width of the rows and the permutation of the columns are usually
defined by a keyword. For example, if the word ZEBRAS is of length
6 (so the rows are of length 6), and the permutation is defined by the
alphabetical order of the letters in the keyword, the order would be "6
3 2 4 1 5"
 Write the message in a rectangle, row by row, and read the message
off, column by column, but permute the order of the columns. The
order of the columns then becomes the key to the algorithm.
Transposition Cipher - Columnar Transposition Cipher
Example: Z E B R A S
Plain Text :
WE ARE DISCOVERED FLEE AT ONCE 6 3 2 4 1 5
Keyword : ZEBRAS W E A R E D
Length of the Key is 6 (6 columns)
Encrypted String : I S C O V E
25 / 6 = 4.5 (approx. 5 rows)
R E D F L E
Order of Alphabet defined in number is E A T O N C
Z E B R A S = 6 3 2 4 1 5
Nulls : X E X X X X X
Cipher Text :
EVLNXACDTXESEAXROFOXDEECXWI
REE
Transposition Cipher - Columnar Transposition Cipher
Columnar Transposition Cipher
How it works?
 In the example, the Keyword is LJEHSVX(4312567).
 Start with the column that is labelled 1, in this case column 3. Write
down all the letters in that column. Proceed to column 4, which is
labelled 2, then column 2, then column 1, then columns 5, 6, and 7.
 A pure transposition cipher is easily recognized because it has the
same letter frequencies as the original plaintext.
Transposition Cipher - Columnar Transposition Cipher
Example: Iteration 1 L J E H S V X
Plain Text :
ATTACK POSTPONED UNTIL TWO AM
4 3 1 2 5 6 7
Keyword : LJEHSVX A T T A C K P
Length of the Key is 7 (7 columns) O S T P O N E
Encrypted String : D U N T I L T
25 / 7 = 3.5 (approx. 4 rows)
W O A M X X X
Order of Alphabet defined in number is
L J E H S V X = 4 3 1 2 5 6 7
Nulls : X
Cipher Text :
TTNAAPTMTSUOAODWCOIXKNLXPETX
Transposition Cipher - Columnar Transposition Cipher
How it can be made complex?
 The transposition cipher can be made significantly more secure by
performing more than one stage of transposition.
 A more complex permutation is created that is not easily
reconstructed.
Transposition Cipher - Columnar Transposition Cipher
Example: Iteration 2 L J E H S V X
Plain Text :
ATTACK POSTPONED UNTIL TWO AM 4 3 1 2 5 6 7
Keyword : LJEHSVX T T N A A P T
Length of the Key is 7 (7 columns) M T S U O A O
Encrypted String :
D W C O I X K
25 / 7 = 3.5 (approx. 4 rows)
N L X P E T X
Order of Alphabet defined in number is
L J E H S V X = 4 3 1 2 5 6 7
Nulls : X
Cipher Text :
N S C X A U O P T T W LT M D N A O I E PA X T T O K X
Practical Activity
 Encrypt “ATTACK AT SIX MORNING”
 Keyword : GERMAN
 Pad Charater : X

Cipher Text : CXNTTRAAOAIIKMGTSN


References
[1] Cryptography and Network Security Principles and Practices by William
Stallings
[2] http://williamstallings.com/NetworkSecurity/NetSec5e-Instructor/ accessed on
25 May 2013
[3] http://www.cs.hofstra.edu/~cscvjc/Spring06/ accessed on 27 May 2013
[4] http://en.wikipedia.org/wiki/Category:Classical_ciphers accessed on 27 May
2013
[5] https://crypto.interactive-maths.com/
[6] Msc. Karwan M. Kareem, Faculty of Physical and Basic Education Computer
Science, University of Sulaimani

You might also like