Cryptography and Network Security
Cryptography and Network Security
Network Security
Chapter 2
Fifth Edition
by William Stallings
Chapter 2 – Classical Encryption
Techniques
128 2128 = 3.4 1038 2127 µs = 5.4 1024 years 5.4 1018 years
168 2168 = 3.7 1050 2167 µs = 5.9 1036 years 5.9 1030 years
26 characters 26! = 4 1026 2 1026 µs = 6.4 1012 years 6.4 106 years
(permutation)
Plain: abcdefghijklmnopqrstuvwxyz
Cipher: DKVQFIBJWPESCXHTMYAUOLRGZN
Plaintext: ifwewishtoreplaceletters
Ciphertext: WIRFRWAJUHYFTSDVFSFUUFYA
Monoalphabetic Cipher
Security
key size is now 25 characters…
now have a total of 26! = 4 x 1026 keys
with so many keys, might think is secure
but would be !!!WRONG!!!
problem is language characteristics
Language Redundancy and
Cryptanalysis
human languages are redundant
e.g., "th lrd s m shphrd shll nt wnt"
letters are not equally commonly used
in English E is by far the most common letter
followed by T,R,N,I,O,A,S
other letters like Z,J,K,Q,X are fairly rare
have tables of single, double & triple letter
frequencies for various languages
English Letter Frequencies
English Letter Frequencies
Sorted Relative Frequencies
14.000
12.000
10.000
8.000
6.000
4.000
2.000
0.000
E T A O I N S H R D L C U MW F G Y P B V K J X Q Z
What kind of cipher is this?
English Letter Frequencies
14.000
12.000
10.000
8.000
6.000
4.000
2.000
0.000
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
14.000
12.000
10.000
8.000
6.000
4.000
2.000
0.000
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
What kind of cipher is this?
English Letter Frequencies
14.000
12.000
10.000
8.000
6.000
4.000
2.000
0.000
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
14.000
12.000
10.000
8.000
6.000
4.000
2.000
0.000
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
Use in Cryptanalysis
key concept - monoalphabetic substitution
ciphers do not change relative letter frequencies
discovered by Arabian scientists in 9th century
calculate letter frequencies for ciphertext
compare counts/plots against known values
if caesar cipher look for common peaks/troughs
peaks at: A-E-I triple, N-O pair, R-S-T triple
troughs at: J-K, U-V-W-X-Y-Z
for monoalphabetic must identify each letter
tables of common double/triple letters help
(digrams and trigrams)
amount of ciphertext is important – statistics!
Example Cryptanalysis
given ciphertext:
UZQSOVUOHXMOPVGPOZPEVSGZWSZOPFPESXUDBMETSXAIZ
VUEPHZHMDZSHZOWSFPAPPDTSVPQUZWYMXUZUHSX
EPYEPOPDZSZUFPOMBZWPFUPZHMDJUDTMOHMQ
Ciphertext = ON UF PH NZ RM BZ
mo -> ON; ve -> UF; fo -> PH, etc.
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
Security of Playfair Cipher
security much improved over monoalphabetic
since have 26 x 26 = 676 digrams
would need a 676 entry frequency table to
analyse (versus 26 for a monoalphabetic)
and correspondingly more ciphertext
was widely used for many years
eg. by US & British military in WW1
it can be broken, given a few hundred letters
since still has much of plaintext structure
Polyalphabetic Ciphers
polyalphabetic substitution ciphers
improve security using multiple cipher alphabets
make cryptanalysis harder with more alphabets
to guess and flatter frequency distribution
use a key to select which alphabet is used for
each letter of the message
use each alphabet in turn
repeat from start after end of key is reached
Vigenère Cipher
simplest polyalphabetic substitution cipher
effectively multiple caesar ciphers
key is multiple letters long K = k1 k2 ... kd
ith letter specifies ith alphabet to use
use each alphabet in turn
repeat from start after d letters in message
decryption simply works in reverse
Example of Vigenère Cipher
write the plaintext out
write the keyword repeated above it
If the key is d plain text is w encryption is z
If the key is e plain text is e encryption is i
use each key letter as a caesar cipher key
encrypt the corresponding plaintext letter
eg using keyword deceptive
key: deceptivedeceptivedeceptive
plaintext: wearediscoveredsaveyourself
ciphertext:ZICVTWQNGRZGVTWAVZHCQYGLMGJ
Security of Vigenère Ciphers
have multiple ciphertext letters for each
plaintext letter
hence letter frequencies are obscured
but not totally lost
start with letter frequencies
see if it looks monoalphabetic or not
if not, then need to determine number of
alphabets, since then can attack each
Frequencies After Polyalphabetic
Encryption
Letter Relative Frequency
14.000
12.000
equiprobable
10.000
unencrypted
8.000
two keys
6.000
four keys
4.000
eight keys
2.000
0.000
Frequencies After Polyalphabetic
Encryption
Sorted relative frequencies
14
12
10 Equiprobible
Unencrypted/1 key
8
two keys
6
four keys
4
eight keys
2
0
1 4 7 10 13 16 19 22 25
Kasiski Method
method developed by Babbage / Kasiski
repetitions in ciphertext give clues to period
so find same plaintext a multiple of key length
apart
which results in the same ciphertext
of course, could also be random fluke
e.g. repeated “VTW” in previous example
distance of 9 suggests key size of 3 or 9
then attack each monoalphabetic cipher
individually using same techniques as before
Example of Kasiski Attack
Find repeated ciphertext trigrams (e.g., VTW)
May be result of same key sequence and same
plaintext sequence (or not)
Find distance(s)
Common factors are likely key lengths
key: deceptivedeceptivedeceptive
plaintext: wearediscoveredsaveyourself
ciphertext:ZICVTWQNGRZGVTWAVZHCQYGLMGJ
Autokey Cipher
A key word is concatenated with the plain text
itself to provide a running key.
ideally want a key as long as the message
Vigenère proposed the autokey cipher
with keyword is prefixed to message as key
knowing keyword can recover the first few letters
use these in turn on the rest of the message
but still have frequency characteristics to attack
eg. given key deceptive
key: deceptivewearediscoveredsav
plaintext: wearediscoveredsaveyourself
ciphertext:ZICVTWQNGKZEIIGASXSTSLVVWLA
Vernam Cipher
Work with binary data rather than latters
Make exclusive or with the data
ultimate defense is to use a key as long as the
plaintext
with no statistical relationship to it
invented by AT&T engineer Gilbert Vernam in
1918
specified in U.S. Patent 1,310,719, issued July
22, 1919
originally proposed using a very long but
eventually repeating key
used electromechanical relays
One-Time Pad
The length of the key is equal to the length of the
massage. The key is not repeated
The new massage will have the new key
if a truly random key as long as the message is
used, the cipher will be secure
called a One-Time pad (OTP)
is unbreakable since ciphertext bears no
statistical relationship to the plaintext
since for any plaintext & any ciphertext there
exists a key mapping one to other
can only use the key once though
problems in generation & safe distribution of key
Transposition Ciphers
now consider classical transposition or
permutation ciphers
these hide the message by rearranging
the letter order
without altering the actual letters used
can recognise these since have the same
frequency distribution as the original text
Rail Fence cipher
write message letters out diagonally over a
number of rows
then read off cipher row by row
eg. write message out as:
m e m a t r h t g p r y
e t e f e t e o a a t
giving ciphertext
MEMATRHTGPRYETEFETEOAAT
Row Transposition Ciphers
is a more complex transposition
write letters of message out in rows over a
specified number of columns
then reorder the columns according to
some key before reading off the rows
Take the column labelled 1, then labelled
2 and so on
Key: 4312567
Column Out 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
Block Transposition Ciphers
arbitrary block transposition may be used
specify permutation on block
repeat for each block of plaintext
Key: 8342067951
Plaintext: attackpost poneduntil twoamxyzab