Lecture02 - Classical Cryptography-1
Lecture02 - Classical Cryptography-1
Network Security
2
Definitions
Plaintext Ciphertext Enciphering/encry
ption
• An original • The coded
message message • The process of
converting from
plaintext to ciphertext
Cryptanalysis Cryptology
• Techniques used for • The areas of
deciphering a message cryptography and
without any knowledge of cryptanalysis
the enciphering details
More Definitions
Unconditional security
– no matter how much computer power or time is
available, the cipher cannot be broken since the
ciphertext provides insufficient information to
uniquely determine the corresponding plaintext
Computational security
– given limited computing resources (eg time
needed for calculations is greater than age of
universe), the cipher cannot be broken
4
Cryptographic Systems
Characterized along three independent
dimensions:
The type of
operations used for The way in which
The number of keys
transforming the plaintext is
used
plaintext to processed
ciphertext
Symmetric,
single-key,
Substitution secret-key, Block cipher
conventional
encryption
Asymmetric,
two-key, or
Transposition Stream cipher
public-key
encryption
Cryptanalysis
6
Cryptanalysis
General approaches:
– cryptanalytic attack
– brute-force attack
7
Cryptanalysis and Brute-Force
Attack
!
所有 都可以发现漏洞
9
low
人
Brute Force Attack
try every single key
most basic attack, proportional to key size
assume either know / recognise plaintext
Key Size (bits) Number of Alternative Time required at 1 Time required at 106
Keys decryption/µs decryptions/µs
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)
10
Model of Symmetric Encryption
11
Symmetric Encryption
12
Symmetric Cryptosystem
A cryptosystem is pair of algorithms that take a key
and convert plaintext to ciphertext and back
Symmetric cryptosystem
– sender and recipient share a common secret key
Mathematically:
Y = EK(X)
X = DK(Y)
13
Symmetric Cryptosystem
⑥
Two requirements:
– a strong encryption algorithm
– a冖secret key known only to sender and receiver
One problem
– how to securely agree with the common key?
Need a secure channel to distribute the common
key
14
Encryption Algorithms
Encryption algorithm is assumed to be known
15
Lecture 2:
Classical Cryptography
Terminology
Classical Encryption Techniques
Key Distribution
Steganography
16
Classical ciphers
Converting plain text to cipher text
Substitution
– Substitute letters of the plain text with other letters/symbol
– Mono/polyalphabetic ciphers
– One-time pad
Transposition
– Rearrange plaintext
17
Substitution
letters of plaintext are replaced by other letters or by
numbers or symbols
monoalphabetic unique mapping of plaintext
alphabet to ciphertext alphabet
– e.g. Caesar, Hill, Playfair
polyalphabetic plaintext mapped to ciphertext
based on key to select alphabet
– e.g. Vigenere, enigma
stream keystream is generated and used to map
plaintext to ciphertext
– e.g. one-time pad
18
Transposition
re-arrange characters (permute)
plain text letters re-arranged, arrays or rail-fence
mematrht g p r y
e t efet eoa a t
MEMATRHTGPRYETEFETEOAAT
19
Others
乘积密码
Product cipher: combining two or more simple
transposition or substitution operations, hoping to
result a more secure encryption
超级加密
Super-encryption: an encryption operation for
which the plaintext input to be transformed is the
ciphertext output of a previous encryption operation
– encrypting encrypted information
20
Caesar Cipher
θ
C = E(k , p ) = (p + k ) mod 26
Where k takes on a value in the range 1 to 25; the decryption
1
algorithm is simply:
p = D(k , C ) = (C - k ) mod 26
文
Cryptanalysis of Caesar Cipher
25
Online Tool
E.g.
https://www.khanacademy.org/computing/computer-
science/cryptography/crypt/p/caesar-cipher-
exploration
http://www.simonsingh.net/The_Black_Chamber/caes
ar.html
27
Sage – Caesar Cipher
28
Monoalphabetic Cipher
Rather than just shifting the alphabet
Could shuffle (jumble) the letters arbitrarily
Each plaintext letter maps to a different
random ciphertext letter
Hence key is 26 letters long
Plain: abcdefghijklmnopqrstuvwxyz
Cipher: DKVQFIBJWPESCXHTMYAUOLRGZN
Plaintext: IfwewIshtoreplaceletters
Ciphertext: WIRFRWAJUHYFTSDVFSFUUFYA
29
Monoalphabetic Cipher Security
31
English Letter Frequencies
32
English Letter Frequencies
Common Bigrams: th, he, in, er, an, re, nd, on, …
Common Trigrams: the, and, ing, her, hat, his, tha, ere, for, ent
Reference: http://norvig.com/mayzner.html
33
Use in Cryptanalysis
Key concept - monoalphabetic substitution ciphers do
not change relative letter frequencies
Discovered by Arabian scientists in the 9th century
Calculate letter frequencies for ciphertext
Compare counts/plots against known values
Cryptanalysis of monoalphabetic ciphers: must
identify each letter
– tables of letter frequencies, and common double/triple letters
help
34
Example Cryptanalysis
Given ciphertext:
UZQSOVUOHXMOPVGPOZPEVSGZWSZOPFPESXUDBMETSXAIZ
VUEPHZHMDZSHZOWSFPAPPDTSVPQUZWYMXUZUHSX
EPYEPOPDZSZUFPOMBZWPFUPZHMDJUDTMOHMQ
Count relative letter frequencies
Guess P & Z are e and t respectively
Guess ZW is th and hence ZWP is the
Proceeding with trial and error finally get:
it was disclosed yesterday that several informal but
direct contacts have been made with political
representatives of the viet cong in moscow
35
Java Code Reference
https://codereview.stackexchange.com/questions/104
863/monoalphabetic-cipher-in-java-with-gui
36
Playfair Cipher
37
Playfair Key Matrix
26 letters are filled into a 5x5 matrix of letters
starting with a keyword
• letters I and J count as one letter
• fill in letters of keyword (ignore duplicates)
• fill rest of matrix with other letters
eg. using the keyword 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
38
Encryption
Plaintext:
• MEET PRIME MINISTER AFTER DINNER
Step 1: Prepare the plaintext
• rewrite the plaintext message in pairs
• ME ET PR IM EM IN IS TE RA FT ER DI NN ER
• all J are replaced with I
• double letters occurring in a pair must be divided by an X or a Z
• e.g. NN becomes NXN
• ME ET PR IM EM IN IS TE RA FT ER DI NX NE R
• if there are an odd number of letters in the plaintext, an extra
letter chosen by the person writing the cipher is added to the
end
• ME ET PR IM EM IN IS TE RA FT ER DI NX NE RX
39
Encryption
Prepared plaintext:
• ME ET PR IM EM IN IS TE RA FT ER DI NX NE RX
Step 2: choose a key, e.g. MONARCHY and create
the key matrix:
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
40
Encrypting
Step 3: plaintext is encrypted two letters at a
time
a. if both letters fall in the same row in the key matrix,
replace each with letter to right (wrapping back to
start from end)
b. if both letters fall in the same column in the key
matrix, replace each with the letter below it (again
wrapping to top from bottom)
c. if the letters are not on the same row or column,
replace them with the letters on the same row
respectively but at the other pair of corners of the
rectangle defined by the original pair. (The order is
important – the first letter of the encrypted pair is the
one that lies on the same row as the first letter of the
plaintext pair).
41
Encryption
Step 3: encrypt
• ME ET PR IM EM IN IS TE RA FT ER DI NX NE RX
• ME same column CL (rule b)
• ET form a rectangle KL (rule c)
• …
• RA same row MR (rule a)
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
42
Encrypting
Step 3: eventually the result becomes
CL KL TO EA LC GA SX LK MR KP KM BK AW MG
AZ
• Example video:
https://www.youtube.com/watch?v=quKhvu2tPy8
43
Decryption
Step 1: Break the ciphertext into pairs of letters
Exercise: decrypt CL KL TO EA LC GA SX LK MR
KP KM BK AW MG AZ using the key MONARCHY
44
Security of Playfair Cipher
Security is much improved over monoalphabetic
since there are 26 x 26 = 676 diagrams
Would need a 676 entry frequency table to
analyse (verses 26 for monoalphabetic)
45
Playfair Cipher in Java
https://rosettacode.org/wiki/Playfair_cipher#Java
46
Polyalphabetic Substitution Ciphers
48
Vigenère Cipher
Simplest polyalphabetic substitution cipher
– effectively multiple Caesar ciphers
51
Security of Vigenère Ciphers
52
Rotor Machines
Before modern ciphers, rotor machines were
most common complex ciphers in use
Widely used in WW2
– German Enigma, Allied Hagelin, Japanese Purple
Implemented a very complex, varying
substitution cipher
Used a series of cylinders, each giving one
substitution, which rotated and changed after
each letter was encrypted
With 3 cylinders have 263=17576 alphabets
53
German Enigma Encryption
Machine
54
Movie – Alan Turning
In 1939, newly created British
intelligence agency MI6 recruits
Cambridge mathematics alumnus
Alan Turing (Benedict
Cumberbatch) to crack Nazi codes,
including Enigma -- which
cryptanalysts had thought
unbreakable.
55
Movie - Alan Turning
56
Hagelin Rotor Machine
57
Soviet cipher machine - Fialka (M-
125) 前苏联
Cipher machines
58
German Lorenz cipher
German Lorenz cipher machine, used in World War
II to encrypt Army Commands messages
59
ACM Turing Award
60
Vernam Cipher
One-Time Pad (OTP) 般 于 常机密
信息的加密
Improvement to Vernam cipher proposed by an Army
Signal Corp officer, Joseph Mauborgne
Use a random key that is as long as the message so that
the key need not be repeated
Key is used to encrypt and decrypt a single message and
then is discarded
Each new message requires a new key of the same length
as the new message
Scheme is unbreakable
– Produces random output that bears no statistical relationship
to the plaintext
– Because the ciphertext contains no information whatsoever
about the plaintext, there is simply no way to break the code
理论上安全
传输密铜
一
用
非
Difficulties
The one-time pad offers complete security but, in practice, has
two fundamental difficulties:
– There is the practical problem of making large quantities of random
keys
• Any heavily used system might require millions of random characters on a
regular basis
– Mammoth key distribution problem
• For every message to be sent, a key of equal length is needed by both
sender and receiver
Because of these difficulties, the one-time pad is of limited utility
– Useful primarily for low-bandwidth channels requiring very high
security
The one-time pad is the only cryptosystem that exhibits perfect
secrecy
theoretically
Transposition Ciphers
giving ciphertext
MEMATRHTGPRYETEFETEOAAT
65
Row Transposition Ciphers
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
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
68
Key Distribution
Session key (short-term keys): 会话密铜
end
– at the conclusion of a session, the key is
destroyed
– if compromised not affecting the long-
term security of the system
静态密铜 Security
Static key (long-term keys): Keepit as shortas
possible
– keys that are to be in use for a long time
period
– if compromised a major problem
69
世
Q1
0
Key Distribution k
T kz
k3
o
0 O
70
Key Distribution
71
Key Distribution
73
metnod to
has drawbacks
– high overhead to hide relatively few info bits
隐藏在像素中 74
大
Example
Bob Smith, my assistant programmer, can always be found
hard at work in his cubicle. Bob works independently, without
wasting company time talking to colleagues. Bob never
thinks twice about assisting fellow employees, and he always
finishes given assignments on time. Often Bob takes extended
measures to complete his work, sometimes skipping coffee
breaks. Bob is a dedicated individual who has absolutely no
vanity in spite of his high accomplishments and profound
knowledge in his field. I firmly believe that Bob can be
classed as a high-caliber employee, the type which cannot be
dispensed with. Consequently, I duly recommend that Bob be
promoted to executive management, and a proposal will be
sent away as soon as possible.
Sd/-
Project Leader
75
Example
Sd/-
Project Leader
77
Another Example
News Eight Weather: Tonight increasing snow. Unexpected
precipitation smothers eastern towns. Be extremely cautious and use
snowtires especially heading east. The highway is not knowingly
slippery. Highway evacuation is suspected. Police report emergency
situations in downtown ending near Tuesday.
78
Digital Techniques
Hide messages (including encrypted message)
in images or videos
Hide data on disk
Hide data/services on Internet
– hackers use non-standard ports for "telnet“
– shell over ICMP (the ping protocol)
– hide bits in network packet headers
– …
Font alterations, word/line shifts
Embed in email headers, pdf file, html doc, etc
79
Steganalysis
Detect/prove stegomessage
Read stegomessage
Remove/jam the stegomessage
Develop a better statistical model of the
cover than the sender
80
Steganography drawbacks and advantages
Drawback Advantage
– It requires a lot of – It can be employed by
overhead to hide a parties who have
relatively few bits of something to lose
information should the fact of their
– Once the system is secret communication
discovered, it becomes (not necessarily the
virtually worthless content) be discovered
– Encryption flags traffic
as important or secret
or may identify the
sender or receiver as
someone with
something to hide
Lecture 2: What you have learnt?
Symmetric Cipher Model
– Cryptography
– Cryptanalysis and Brute-Force Attack
Transposition techniques
Rotor machines
Substitution techniques
– Caesar cipher
– Monoalphabetic ciphers
– Playfair cipher
– Polyalphabetic ciphers
– One-time pad
Steganography
82
Assignment 2
cryptography-and-network-security_-principles-and-
practice-7th-global-edition.pdf
83