Professional Documents
Culture Documents
by
KAVITHA C.R.
Asst. Prof.
Dept. of Computer Science and Engineering
Notations:
P – Plain Text
C – Cipher Text
Cryptosystem
(P, C, K, E, D)
P – Plain Text
C – Cipher Text
K – Secret key
E – Encryption Algorithm
D – Decryption Algorithm
29-10-2022 2
There are various techniques.
Encryption: Ci = Pi + K mod 26
Decryption: Pi = Ci – K mod 26
a b c d …… is 0, 1, 2,3………
29-10-2022 3
Cryptanalysis
Cryptanalysis is the art of breaking codes and ciphers.
29-10-2022 4
Given the cipher text, find plain text and the key using brute force attack
WXUWOHVFDQWHOOPRUHDERXWWKHURDGVWKDVWTVNUHV
-1 VWTVN
-2 UVSUM
-3 TURTLESCANTELLMOREABOUTTHEROADSTHANHARES
29-10-2022 5
2)
29-10-2022 6
Eg.1: P = givesomemoney
K=7
Find C.
29-10-2022 7
Decryption of C = QERCWUGCGUNCM with k = 7, so its inverse K-1 is 15
29-10-2022 8
3) Simple Substitution Cipher
Encryption
plaintext : defend the east wall of the castle
ciphertext : giuifgceiiprctpnnduceiqprcni
Decryption
29-10-2022 10
Cryptanalysis
The simple substitution cipher is quite easy to break.
Even though the number of keys is around 288.4 (a really
big number), there is a lot of redundancy and other
statistical properties of English text that make it quite easy
to determine a reasonably good key.
The first step is to calculate the frequency distribution of
the letters in the cipher text.
This consists of counting how many times each letter
appears.
Note: Brute Force Attack takes 26!
29-10-2022 11
Natural English text has a very distinct distribution that can be used help
crack codes. This distribution is as follows:
29-10-2022 12
Short pieces of text often need more expertise to crack.
If the original punctuation exists in the message,
e.g. 'giuifg cei iprc tpnn du cei qprcni’,
then it is possible to use the following rules to guess some of the words, then,
using this information, some of the letters in the cipher alphabet are known.
One-Letter Words
a, i
Frequent Two-Letter Words of, to, in, it, is, be, as, at, so, we, he, by, or,
on, do, if, me, my, up, an, go, no, us, am
the, and, for, are, but, not, you, all, any,
can, had, her, was, one, our, out, day, get,
Frequent Three-Letter Words has, him, his, how, man, new, now, old,
see, two, way, who, boy, did, its, let, put,
say, she, too, use
that, with, have, this, will, your, from, they,
Frequent Four-Letter Words
know, want, been, good, much, some, time
29-10-2022 13
Usually, punctuation in ciphertext is removed and the ciphertext is put
into blocks such as 'giuif gceii prctp nnduc eiqpr cnizz', which prevents
the previous tricks from working. There are, however, many other
characteristics of English that can be utilized. The table below lists
some other facts that can be used to determine the correct key. Only
the few most common examples are given for each rule.
Most Frequent Single Letters ETAOINSHRDLU
th er on an re he in ed nd ha at en
Most Frequent Digraphs es of or nt ea ti to it st io le is ou ar
as de rt ve
the and tha ent ion tio for nde has
Most Frequent Trigraphs
nce edt tis oft sth men ing
Most Common Doubles ss ee tt ff ll mm oo
TOAWBCDSFMRHIYEGLN
Most Frequent Initial Letters
PUJK
ESTDNRYFLOGHAKMPU
Most Frequent Final Letters
W
29-10-2022 14
SOWFBRKAWFCZFSBSCSBQITBKOWLBFXTBKOWLSOXS
OXFZWWIBICFWUQLRXINOCIJLWJFQUNWXLFBSZXFBTX
AANTQIFBFSFQUFCZFSBSCSBIMWHWLNKAXBISWGSTO
XLXTSWLUQLXJBUUWLWISTBKOWLSWGSTOXLXTSWL
BSJBUUWLFULQRTXWFXLTBKOWLBISOXSSOWTBKOWL
XAKOXZWSBFIQSFBRKANSOWXAKOXZWSFOBUSWJBSB
FTQRKAWSWANECRZAWJ
Encryption Table
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
X Z T J W U M O B E P A R I Q K D L F S C H Y G N V
THESIMPLESUBSTITUTIONCIPHERISACIPHERTHATHASBEEN
INUSEFORMANYHUNDREDSOFYEARSITBASICALLYCONSISTS
OFSUBSTITUTINGEVERYPLAINTEXTCHARACTERFORADIFFER
ENTCIPHERTEXTCHARACTERITDIFFERSFROMCAESARCIPHER
INTHATTHECIPHERALPHABETISNOTSIMPLYTHEALPHABET
SHIFTEDITISCOMPLETELYJUMBLED
29-10-2022 15
Z A Z M I T A K A V O A I O L
h e h a d s e l e c t e d t w
Y A X M Q G K A T Y B T O P I
o e x a m p l e s o f s t u d
A S O V Y Q G Y T D O D Y S O
e n t c o m p o s i t i o n t
Z A B D J T O L M T M J M Q N
h e f i r s t w a s a r a m b
K D S E I D T V Y S S A V O A
l i n g d i s c o n n e c t e
I O Z D S E L D O Z D S O A J
d t h i n g w i t h i n t e r
A T O D S E D I A M T O Z M O
e s t i n g i d e a s t h a t
S A W A J N P D K O D S O Y M
n e v e r b u i l t i n t o a
S U O Z D S E
16
29-10-2022 n y t h i n g
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
e f j i g k p q d r l w a b t u m z n s y c v x o h
29-10-2022 17
Affine Cipher
(k1, k2) key pair is used
k1 is the multiplicative key and k2 is the additive key
Encryption: C = P * k1 + k2 mod 26
29-10-2022 18
19
29-10-2022
29-10-2022
7-1 mod 26 is 15 20
Encryption
29-10-2022 21
Brute Force Attack
Multiplication operation
Փ(26) = 12
K1= z26* = {1,3,…….25}
So 12 elements
Addition operation
Key space = 26
K2 = z26 = {0, 1,….25}
But 0 will not be used.
Then key space = 25
11 * 25 = 275 possible
29-10-2022
keys 22
Suppose we receive a cipher text that was
enciphered using an Affine cipher. After running a
frequency analysis on cipher text, we found that the
most highly frequency occurring letters are R and K.
Assume that these letters corresponds to e and t.
Find the parameters that were used in Affine cipher.
Given Cipher text C is FMXVEDKAPH
Index Table
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 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
29-10-2022 23
29-10-2022 24
3-1 mod 26 is 9
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 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 25
The plaintext obtained is algorithms
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 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
26
29-10-2022 27
29-10-2022 28
29-10-2022 29
Message is Have a good day
ha ve ag oz od da yz
CD OM BL XT SB BL ZP
same letter should not be repeated in a digram. Use a filler character to separate.
29-10-2022 30
Key is KEYWORD
K E Y W O
R D A B C
F G H I/J L
M N P Q S
T U V X Z
1) Why don’t you?
wh yd on ty ou
YI EA ES VK EZ
YJ
2) come to the window
co me to th ew in do wy
OZ NK ZK VF YO GQ CE YE
Index table
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 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2
29-10-2022 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 32
29-10-2022 33
Vigenere
Table
29-10-2022 34
Eg. 1: The key is KEY, and the plaintext is DCODE. What is the
cipher text?
C1 = 3 + 10 mod 26 = 13 N
C2= 2 + 4 mod 26 = 6 G
C3= 14 + 24 mod 26 = 12 M
C4 = 3 + 10 mod 26 = 13 N
C5 = 4 + 4 mod 26 = 8 I
0 1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
29-10-2022 35
How to find the key when having both cipher and
plaintext?
When encrypting, the key is added to the plain text to get
encrypted text. So, from the encrypted text, subtract the
plain text to get the key.
Ci = Pi + Ki mod 26 Then, Ki = Ci – Pi mod 26
Eg. 3: Plain text : is it safe
Cipher text: awknjexi
Find the key. security
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 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
29-10-2022 36
Cryptanalysis of Vigenere Cipher
29-10-2022 37
How to decipher Vigenere without knowing the key?
Kasiski test
Kasiski test consists in finding repeating sequences of
letters in the ciphertext.
38
29-10-2022
If K matrix is used for encryption then K-1 Matrix is used for decryption
29-10-2022 Matrix inverse exists if its determinant is not equal to 0 39
Encrypt the message “heie” using Hill cipher with the given
Key matrix.
Aij= a b AijT= a c
K=3 7 c d b d
5 12 Aij-1= d -b
-c a
Its inverse exists, it is K-1 = 12 -7 divided by the
Aij = (-1)i+j subdeterminant with
-5 3 determinant mod 26 row i and col j
__________________________
det(A)
Decryption
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 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
29-10-2022 41
29-10-2022
42
A: 10010010111 00010111001
B: 01111010001 10010010111
A xor B :00010111001 01111010001
Why is it Unbreakable?
The key is unbreakable owing to the following features −
•The key is as long as the given message.
•The key is truly random and specially auto-generated.
•Key and plain text calculated as modulo 10 or 26 or 2.
•Each key should be used once and destroyed by both sender and receiver.
•There should be two copies of key: one with the sender and other with the
receiver.
P 3 1 4 5 2 P 1 2 3 4 5
C 1 2 3 4 5 C 2 5 1 3 4
29-10-2022 49
29-10-2022 50
29-10-2022 51
Encryption Key Decryption Key
31452 25134
29-10-2022 52
Decryption Key matrix is the multiplicative inverse of Key matrix and
K * K-1 mod 26 = Identity Matrix
29-10-2022 53
29-10-2022 54
1) Encrypt the text “sources” using Hill cipher and given the key
matrix and verify the decryption.
K=9 4 18 14 9 4 mod 26 = 24 14 = yo fr mk bn
5 7 20 17 * 5 7 5 17
2 4 12 10
18 25 1 13
Decryption: inverse of K mod 26.
7 -4
-5 9 divided by 43 * cipher text mod 26
43-1 mod 26 = 17-1 mod 26 = 23
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 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2
29-10-2022 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 55
Plain Text = “ Sources”
K=9 4
5 7
Encryption:
C = K P mod n
C1 = 9 4 18 9 * 18 + 4 * 14 10 K
C2 5 7 * 14 mod 26 = 5 * 18 + 7 * 14 mod 26 = 6 = G
C3 = 9 4 20 9 * 20 + 4 * 17 14 O
C4 5 7 * 17 mod 26 = 5 * 20 + 7 * 17 mod 26 = 11 = L
and so on
56
29-10-2022
2) Encrypt the message “cryptography is good” using the permutation
cipher using the given encryption table. Find the decryption key.
C 1 2 3 4 5
Decryption key is 1 4 2 5 3
P 1 3 5 2 4
1 3 5 2 4
c r y p t
o g r a p COHOYRIDTPGZRGYOPASX
h y i s g
o o d x z
29-10-2022 57
3) Decrypt the cipher text which has been encrypted using Permutation or
Transposition cipher.
SRNTAGTAEHTRACETRSUEWTOIHUBCTAKOEBNSAEHVTE
AHHRETDSSELHLS
Hint1: 5 is the key length
Hint2: 4 filler characters are required
Hint3: Block cipher
29-10-2022 58
4) Decrypt the following cipher text using the key “BENEFIT” and
single round columnar transposition.
KEDEEXHFZAOXSUYYNYBNZ
Hint1: find the message length and divide by key length to get no. of rows
Write column wise based on key and then read row wise.
1 2 6 3 4 5 7
B E N E F I T
K E Y H A S B
E E N F O U N
D X Y Z X Y Z
29-10-2022 Note: The key characters decide the order of cipher text
59
5) Perform columnar double transposition using the same key “STRENGTH”
Plain text is “meet me later”
First Round
6 7 5 1 4 2 8 3
S T R E N G T H
M E E T M E L A
T E R X Y Z W X
Second Round
6 7 5 1 4 2 8 3
S T R E N G T H
T X E Z A X M Y
E R M T E E L W
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
c w m l h u d r p k j
29-10-2022 61
Homophonic Substitution Cipher
Homophonic Substitution cipher is a substitution cipher in which single plaintext
letters can be replaced by any of several different ciphertext letters. They are
generally much more difficult to break than standard substitution ciphers
• The number of characters each letter is replaced by is part of the key,
e.g. the letter 'E' might be replaced by any of 5 different symbols, while
the letter 'Q' may only be substituted by 1 symbol.
63
29-10-2022
Attacks
Types of Attacks
1) Active Attacks
2) Passive Attacks
29-10-2022 64
Modification In Active Attack, information is In Passive Attack, information
1 modified. remain unchanged.
Dangerous For Active Attack is dangerous for Passive Attack is dangerous for
2 Integrity as well as Availability. Confidentiality.
Victim Victim gets informed in active Victim does not get informed in
5 attack. passive attack.
29-10-2022 69
10) Timing Attacks −
▪ They exploit the fact that different computations take
different times to compute on processor.
▪ By measuring such timings, it is be possible to know about
a particular computation the processor is carrying out.
▪ For example, if the encryption takes a longer time, it
indicates that the secret key is long.