Lec 2 - Classical Encryption
Lec 2 - Classical Encryption
Lec 2 - Classical Encryption
Dr Shahzaib Tahir
shahzaib.tahir@mcs.edu.pk
Lecture 2
Introduction
• Information has to be concealed from an unauthorised
person (attacker), so that in the event that it is
passively accessed (e.g., copied or intercepted) by an
attacker, it should not be useful to them
• Hiding Techniques
– Steganography
– Cryptography
Steganography
• Steganography is the study of hiding critical information within
some less important information:
– Hidden messages on messenger's body, Using invisible ink,
pin punctures, Digital steganography etc.
– If the less important information is revealed, the attacker
should not be able to even identify, let alone extract, the
critical information
3
3rd March
Dear George,
Greetings to all at Oxford. Many thanks for your
letter and for the Summer examination package.
All Entry Forms and Fees Forms should be ready
for final despatch to the Syndicate by Friday
20th or at the very latest, I'm told, by the 21st.
Admin has improved here, though there's room
for improvement still; just give us all two or three
more years and we'll really show you! Please
don't let these wretched 16+ proposals destroy
your basic O and A pattern. Certainly this
sort of change, if implemented immediately,
would bring chaos.
Sincerely yours,
“A Puzzle for Inspector Morse”, (Originally from “The Silent World of Nicholas
Quinn”, by Colin Dexter)
Message: Your package ready Friday 21st room three please destroy immediately.
What is Encryption
• Encryption is the process of encoding a message or information in
such a way that only authorized parties can access it
10
Requirements of Classical Encryption
12
Model of Symmetric Crypto-System
Security of Symmetric Algos
• We assume that it is impractical to decrypt a message on the
basis of the ciphertext plus knowledge of the
encryption/decryption algorithm
• In other words, we do not need to keep the algorithm secret;
we need to keep only the key secret
• This feature of symmetric encryption is what makes it feasible
for widespread use
• The fact that the algorithm need not be kept secret means
that manufacturers can and have developed low-cost chip
implementations of data encryption algorithms
• With the use of symmetric encryption, the principal security
problem is maintaining the secrecy of the key
Cracking the Crypto System
• Cryptanalysis
– Cryptanalytic attacks rely on
• nature of the algorithm
• some knowledge of the general characteristics of the plaintext
• some sample plaintext–ciphertext pairs
– These attacks try to deduce a specific plaintext or to
deduce the key being used
• Brute-force attack
– The attacker tries every possible key on a piece of
ciphertext until an intelligible translation into plaintext is
obtained
– On average, half of all possible keys must be tried to
achieve success.
Cipher Text Only Attack
• Available
– Ciphertext
– Encryption algorithm (public)
• Approach
– Brute-force Attack – try all possible keys
– Statistical Testing – Idea of type of plaintext being
concealed (English text, an EXE file, accounting file
etc.)
Known Plaintext Attack
• The analyst may be able to capture one or more
plaintext messages as well as their encryptions, he’s
given, he’s not choosing.
• The attacker cannot produce more plaintext-ciphertext
pairs, he has to obtain them from whoever has the key
• Or the analyst may know that certain plaintext patterns
will appear in a message (Example Baker Street)
– Standardized Header
– Specific Patterns etc.
• With this knowledge, the analyst may be able to deduce
the key on the basis of the way in which the known
plaintext is transformed
Chosen Plaintext Attack
• Available
– Ciphertexts chosen by cryptanalyst
– Corresponding plaintexts.
– Encryption algorithm (public)
• Example:
– A poorly designed file storage system uses the same
key to encrypt everyone's files, and lets anyone see
anyone's files (in encrypted form). Eve knows Bob
uses the service, she registers as well and starts
encrypting arbitrary files (which she can choose) and
looks at the resulting ciphertext. From this she obtains
the service's encryption key, and decrypts Bob's stuff
Chosen Ciphertext Attack
• Available
– Ciphertexts chosen by cryptanalyst
– Corresponding plaintexts.
– Encryption algorithm (public)
• Example
– Eve breaks into Bob's house while he is sleeping, and
replaces the ciphertext he was going to send to Alice
tomorrow with a new one of her choosing. She then
eavesdrops on their communications (encrypted or
not) the next day to try and work out what Alice read
when she decrypted the fake ciphertext (variants of
this involve Eve not just creating a new ciphertext, but
modifying the existing one slightly).
• Less commonly employed as cryptanalytic technique but
is nevertheless possible avenue of attack.
Computationally Secure Encryption
• An encryption scheme is said to be computationally
secure if either of the following two criteria are met
– 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
• An important thing to know about Brute force attacks is
that unless known plaintext is provided, the analyst must
be able to recognize plaintext as plaintext.
Classical Substitution Ciphers
• Letters/bits of plaintext are replaced by other letters/bits.
• Categorized as:
1. Monoalphabetic Ciphers
• Uses fixed substitution over the entire message.
• Example: Ceaser Cipher
2. Polyalphabetic Ciphers
• uses a number of substitutions at different positions
in the message, where a unit from the plaintext is
mapped to one of several possibilities in the
ciphertext and vice versa.
• Example: Vigenere cipher
Cont…
3. Homophonic Ciphers
• involves replacing each letter with a variety of
substitutes, the number of potential substitutes being
proportional to the frequency of the letter.
• Example: Beale Ciphers
4. Polygram Ciphers
• In this, group of letters are encrypted together, and
includes enciphering large blocks of letters. Therefore,
permits arbitrary substitution for groups of characters.
• Example: Playfair cipher
Some examples
a mod n = r
• -4 mod 9 = -4 + 9 = 5 (Since 9 does not divide -4. Just
add 9 to make positive)
• 4 mod 9 = 4
• -49 mod 5 = - 4 + 5 =1 (divide -49 by 5 then add 5 to
make positive)
• 14 mod 2 = 0
• 49 mod 5= 4
• -9 mod 6 = -3 + 6 = 3 (divide -9 by 6=-3 then add 6 to
make positive)
• -6 mod 18 = -6 + 18 = 12 (since -6 is not divisible by 18.
Just add 18 and compute)
23
Monoalphabetic Ciphers
Caesar Cipher
• The earliest known, and the simplest, use of a substitution cipher
was by Julius Caesar.
• The Caesar cipher involves replacing each letter of the alphabet
with the letter standing three places further down the alphabet.
• Then the algorithm can be expressed as follows. For each plaintext letter p,
substitute the ciphertext letter
C = E(3, p) = (p + 3) mod 26
• A shift may be of any amount, so that the general Caesar algorithm is,
C = E(k, p) = (p + k) mod 26
• Here, k takes on a value in the range 1 to 25. The decryption algorithm is
simply
Decrypting Caesar Cipher
• The decryption algorithm is simply
p = D(k, C) = (C - k) mod 26
• The longer the text, the closer the letter frequency distributions
match the language’s actual letter frequency distributions
• Ciphertext:
R jrk hbxiu lk vai vzihova ohlls lo rk rmrsvjikv ywbhtbkn.
Ixise jlskbkn ai vrgiu vai ihixrvls tlzk vl vai hlyye rkt hirxiu vai
ywbhtbkn. Bk vai ixikbkn, ai nivu bkvl vai ihixrvls, rkt, bo
vaisi bu uljilki ihui bk vai ihixrvls -- ls bo bv zru srbkbkn varv
tre -- ai nliu yrpg vl abu ohlls tbsipvhe. Alzixis, bo vaisi bu
klylte ihui bk vai ihixrvls rkt bv aruk'v srbkit, ai nliu vl vai
vikva ohlls rkt zrhgu wm vzl ohbnavu lo uvrbsu vl abu sllj.
31
Example (cont …)
Letter A B C D E F G H I J K L M
Frequency 23 26 0 0 5 0 3 18 49 5 26 32 2
Letter N O P Q R S T U V W X Y Z
Frequency 9 10 2 0 24 19 11 19 37 3 9 6 6
Example (cont …)
• Letter Frequencies
Blue: English’s
Frequency
Green: Cipher’s
Frequency
Example (cont …)
• From the frequency distributions, we assume that:
– C(I) -> P(E) matching relative frequencies
34
Example (cont …)
• From the frequency distributions, we assume that:
– C(V) -> P(T) matching relative frequencies
35
Example (cont …)
39
Example (cont …)
• We can assume that C(R) -> P(A) because:
– The word “THAT” is the only frequently used 4-letter English
word starting with ‘TH’ and ending with T
40
Example (cont …)
• We can assume that C(K) -> P(N) because:
– The words “AN” and “AT” are the only frequently used 2-letter
English words starting with A
– The relative frequency of K in the ciphertext closely approximates
the relative frequency of N in English
• Partially decrypted ciphertext (red = plaintext):
• A jak hbxeu lk the tzehoth ohlls lo ak amastjekt
ywbhtbkn. Exese jlskbkn he tageu the ehexatls tlzk
tl the hlyye akt heaxeu the ywbhtbkn. Bk the
exekbkn, he netu bktl the ehexatls, akt, bo these
bu uljelke ehue bk the ehexatls -- ls bo bt zau
sabkbkn that tae -- he nleu yapg tl hbu ohlls
tbsepthe. hlzexes, bo these bu klylte ehue bk the
ehexatls akt bt hauk't sabket, he nleu tl the tekth
ohlls akt zahgu wm tzl ohbnhtu lo utabsu tl hbu
sllj.
41
Example (cont …)
• We can assume that C(K) -> P(N) because:
– The words “AN” and “AT” are the only frequently used 2-letter
English words starting with A
– The relative frequency of K in the ciphertext closely approximates
the relative frequency of N in English
• Partially decrypted ciphertext (red = plaintext):
• A jan hbxeu ln the tzehoth ohlls lo an amastjent
ywbhtbnn. Exese jlsnbnn he tageu the ehexatls tlzn
tl the hlyye ant heaxeu the ywbhtbnn. Bn the
exenbnn, he netu bntl the ehexatls, ant, bo these
bu uljelne ehue bn the ehexatls -- ls bo bt zau
sabnbnn that tae -- he nleu yapg tl hbu ohlls
tbsepthe. hlzexes, bo these bu nlylte ehue bn the
ehexatls ant bt haun't sabnet, he nleu tl the tenth
ohlls ant zahgu wm tzl ohbnhtu lo utabsu tl hbu
sllj.
42
Example (cont …)
• We assume that:
– C(T) -> P(D) (from the word ‘ant’)
43
Example (cont …)
• We assume that:
– C(T) -> P(D) (from the word ‘ant’)
44
Example (cont …)
• We assume that:
– C(B) -> P(I) (from the words ‘bt’ and ‘bn’)
45
Example (cont …)
• We assume that:
– C(B) -> P(I) (from the words ‘bt’ and ‘bn’)
46
Example (cont …)
• If you continue like this, you will eventually obtain a complete
decryption of the message and will also have recovered the key
(the substitution alphabet)
Analysis:
Monoalphabetic ciphers are easy to break because they reflect the
frequency data of the original alphabet. A countermeasure is to
provide multiple substitutes
47
What is Affine Cipher
3/14/2022 61
Decrypting
• Now, the next step is to compute 21(y − 8),
and then take the remainder when that
result is divided by 26. The following table
shows the results of both computations
Decrypting
• The final step in decrypting the ciphertext
is to use the table to convert numeric
values back into letters. The plaintext in
this decryption is AFFINECIPHER. Below
is the table with the final step completed.
Homophonic Ciphers
Homophonic Ciphers
• Replacing each letter with a variety of
substitutes (homophones) where a
homophone is used in rotation or chosen
randomly and the number of potential
substitutes are proportional to the
frequency of the letter.
Example
A
B
• pt: defending against C
D
frequency analysis attacks E
F
• CT: 45 14 31 87 66 01 73 G
H
59 25 09 06 78 88 71 11 I
J
49 10 40 98 94 63 46 58 K
L
41 52 12 58 53 26 21 19 M
N
73 36 33 20 69 67 62 04 O
P
76 Q
R
S
T
U
V
W
X
Y
Z
Algorithm Security
• Breaking homophonic substitution ciphers can be very difficult if the
number of homophones is high
69
Playfair Key Matrix
• Use a 5 x 5 matrix.
• Fill in letters of the key (w/o duplicates).
• Fill the rest of matrix with other letters.
• E.g., key = MONARCHY.
M O N A R
C H Y B D
E F G I/J K
L P Q S T
U V W X Z
70
Encrypting and Decrypting
Plaintext is encrypted two letters at a time.
1. If a pair is a repeated letter, insert filler like 'X’.
2. If both letters fall in the same row, replace
each with the letter to its right (circularly).
3. If both letters fall in the same column, replace
each with the letter below it (circularly).
4. Otherwise, each letter is replaced by the letter
in the same row but in the column of the other
letter of the pair.
71
Green = plaintext
Red = ciphertext
Rules: encryption
72
Polygram Cipher: Playfair
• Playfair technique encrypts pairs of letters (digraphs), instead of
single letters as in the simple substitution cipher. The Playfair is
significantly harder to break since the frequency analysis used for
simple substitution ciphers does not work with it
R D A B C
F G H I L
M N P Q S
T U V X Z
Preparing your Message
• Split PT into pairs
• Separate all duplicated letters by inserting "X"
• If there is an odd letter at the end of message, insert letter "X"
• Ignore all spaces
• IF in same ROW
– Move each letter right ONE
– Upon reaching the end of table, wrap around
• IF it forms a Rectangle
– Swap the letters with the ones on the end of
the rectangle
Example (cont)
SE CR ET ME SX SA GE
K E Y W O
Rule 3:
R D A B C SE
Swap letters
with one on
end of the F G H I L NO
rectangle
M N P Q S
T U V X Z
Example (cont)
SE CR ET ME SX SA GE
K E Y W O
Rule 2: CR
R D A B C
Move each
letter right
F G H I L RD
M N P Q S
T U V X Z
Example (cont)
SE CR ET ME SX SA GE
K E Y W O
Rule 3:
R D A B C ET
Swap letters
with one on
end of the F G H I L KU
rectangle
M N P Q S
T U V X Z
Example (cont)
SE CR ET ME SX SA GE
K E Y W O
Rule 3:
Swap letters
R D A B C ME
with one on
end of the F G H I L NK
rectangle
M N P Q S
T U V X Z
Example (cont)
SE CR ET ME SX SA GE
K E Y W O
Rule 3:
R D A B C SX
Swap letters
with one on
end of the F G H I L QZ
rectangle
M N P Q S
T U V X Z
Example (cont)
SE CR ET ME SX SA GE
K E Y W O
Rule 3:
R D A B C SA
Swap letters
with one on
end of the F G H I L PC
rectangle
M N P Q S
T U V X Z
Example (cont)
SE CR ET ME SX SA GE
K E Y W O
Rule 1:
R D A B C GE
Move each
letter down
ONE F G H I L ND
M N P Q S
T U V X Z
Finally….
Orignal Text:
• SECRET MESSAGE
• SECRETMESSAGE
• SE CR ET ME SX SA GE
Cipher Text
• NO RD KU NK QZ PC ND
• NORDKUNKQZPCND
Polyalphabetic Ciphers
Vigenere Cipher
Find the intersection point of the keyword and plaintext in the vigenere
table
• The Kasiski examination involves looking for strings of characters that are
repeated in the ciphertext. The strings should be three characters long or
more for the examination to be successful
• Thus finding more repeated strings narrows down the possible lengths of
the keyword, since we can take the greatest common divisor of all the
distances.
Finding Repetitive Distance
Key Length Estimate
• Encryption key determined from repetitive distances is 2,3,6 or 9
• Eve assumes the key length to be 6
..contd
..contd
..contd
..contd
..contd
..contd
..contd
..contd
Transposition Ciphers
Background
• All the techniques examined so far involve the substitution of a
ciphertext symbol for a plaintext symbol
• To decrypt, all one must do is wrap the leather strip around the rod and read
across. The ciphertext is: "IryyatbHmvaEhedLurlP" Every fifth letter will
appear on the same line, so the plaintext is extracted
Rail-fence Cipher
• The simplest such cipher is the rail fence
technique, in which the plaintext is written
down as a sequence of diagonals and
then read off as a sequence of rows
Encryption
• For the plaintext, "defend the east wall", with a key of 3, we get the
encryption process shown below
Key: 4 3 1 2 5 6 7
Plaintext: a t t a c k p
o s t p o n e
d u n t i l t
w o a m x y z
Ciphertext: TTNAAPTMTSUOAODWCOIXKNLYPETZ
Example
• Decrypt where K: 7416352
– CT: STTMNKGUESNXNEEIDWAEE
– No of rows = 21/7=3
7 4 1 6 3 5 2
A S S I G N M
E N T D U E N
E X T W E E K
• The process of
decryption with a Feistel
cipher is essentially the
same as the encryption
process.
• Ciphertext is used as
input to the algorithm,
but subkeys Ki are used
in reverse order.