Cryptography Module 1part 2
Cryptography Module 1part 2
2
Module 1: Introduction to Cryptography and types of
Ciphers
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.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
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
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
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
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:
Dividing the result into 5-letter blocks. As a result, the above plaintext and
keyword become the following:
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
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
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
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
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
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
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
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
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
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
Key Matrix =
D=3
Hill Cipher Decryption: Example 3
Step 2: Calculate the multiplicative inverse for the determinant.
dd-1
1 mod 26
d * d-1 mod 26 =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 3
Step 2: Multiply multiplicative inverse of the determinant with adjoint matrix
Key: AHELATPBA
Ciphertext: SYICHOLER
Hill Cipher – Decryption: Example 3x3 Key matrix
Step 1: Calculate the multiplicative inverse for the determinant.
1 mod 26
dd-1
d * d-1 mod 26 =1
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