Introcryptography 1
Introcryptography 1
Introduction to Cryptography
Dr. Khaled Tarmissi
[email protected]
Office: 1160 Lecture : #1
What is Cryptography?
1
12/2/2023
3. Mathematics of Cryptography
5. Stream cipher
2
12/2/2023
Reference Materials
Grading (Tentative)
3
12/2/2023
Warnings
4
12/2/2023
Formal requirements
• Probability
• Algorithms and complexity
• Combinatorics
• Number theory
• …
Background • etc
necessary
for the For the purpose of this course,
course a brief overview of the needed
concepts will be given to refresh
your memory. However, a
minimum level of mathematical
maturity is assumed
1
0
Cryptology
Overview of
Cryptology
Cryptography Cryptanalysis
• Cryptology
• Greek: “krypto” = hide
• Cryptology –science of hiding
• Cryptology = cryptography +
cryptanalysis
10
5
12/2/2023
Cryptography ⎯ making
“secret codes”
Crypto
Cryptanalysis ⎯ breaking
“secret codes”
11
11
• today?
12
6
12/2/2023
usage server.
• • SSL uses cryptography
13
Cryptography
usage Other uses of cryptography
ATM machines
On-line banking
•…
• etc.
14
14
7
12/2/2023
Alice
Bob
15
16
16
8
12/2/2023
17
17
Goals of Cryptography
❖ Cryptography is the science that enables Alice
and Bob to communicate securely in the
presence of Eve
❖ Goals
✓ Confidentiality : Protection from disclosure to unauthorized persons
✓ Data integrity : Maintaining data consistency
✓ Authentication: Entity authentication (Identification) and Message
authentication (Data origin authentication)
✓ corroborating the source of information
✓ Non-repudiation : Originator of communications can’t deny it later
18
18
9
12/2/2023
Basic Terminology
19
20
10
12/2/2023
21
21
Single-key
22
22
11
12/2/2023
23
Substitution cipher
Caesar Cipher
• Earliest known
substitution cipher
• Invented by Julius
Caesar
• Each letter is replaced
by the letter three
positions further
down the alphabet.
24
24
12
12/2/2023
25
Plaintext ab c d e f g h i j k l mn o p q r s t u v w x y z
Ciphertext D E F G H I J K L MN O P Q R S T U VWX Y Z A B C
26
26
13
12/2/2023
Caesar Cipher
27
27
28
28
14
12/2/2023
Shift Cipher
29
Shift Cipher
Example
P = CRYPTOGRAPHY IS FUN
K = 19
Steps
C → 2; 2+19 mod 26 = 21 → V
R → 17; 17+19 mod 26 = 10 → K
…
…..
N → 13; 13+19 mod 26 = 6 → G
C = VKRIMHZKTIAR BL YNG
30
30
15
12/2/2023
31
31
32
16
12/2/2023
Shift Cipher
Plain-text: S E N D R E I N F O R C E M E N T
Key: 2
Cipher-text: U G P F T F K P H Q T E G O G P V
33
33
Plaintext: ifwewishtoreplaceletters
Ciphertext: WIRFRWAJUHYFTSDVFSFUUFYA
• What does a key look like???
34
34
17
12/2/2023
Plaintext ab c d e f g h i j k l mn o p q r s t u v w x y z
Ciphertext J I C A X S E Y V D KWB QT Z R H F M P N U L GO
35
35
36
36
18
12/2/2023
37
Frequency analysis
38
38
19
12/2/2023
Example
HereUpOnLeGrandAroseWithAGraveAndStatelyAirAndBrought
Here
He e e r
ra a e h
ha a eea t t
tat a r
ra r ht
LIVITCSWPIYVEWHEVSRIQMXLEYVEOIEWHRXEXIPFEMVEWHKVSTYLX
MeTheBeetleFromAGlassCaseInWhichItWasEnclosedItWasABe
ethe eet e r a a e h h t a e e t a a e
ZIXLIKIIXPIJVSZEYPERRGERIMWQLMGLMXQERIWGPSRIHMXQEREKI
I – most common letter I=e L=h X=t
LI – most common pair V=r E=a Y=g
XLI – most common triple
39
39
40
40
20
12/2/2023
41
41
42
42
21
12/2/2023
43
43
brute-force attack
Two general
non-brute-force attack
approaches:
(cryptanalytic attack)
44
44
22
12/2/2023
Polyalphabetic Cryptosystems
45
45
Vigenere Cipher
▪ Simplest polyalphabetic substitution
cipher
▪ Effectively multiple shift ciphers
▪ key is multiple letters long K = k1 k2 ... Kd
▪ The key is a vector of shifts … SO .. the key
and its length are unknown to Eve.
▪ 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
46
46
23
12/2/2023
Vigenere Example :
47
47
Vigenere Cipher
• “Multi-Caesar Cipher” – A statefull cipher
Key: k = (k1,k2,…,km) list of m numbers between 0 and 25
Encryption: n1thstletter
letter
encoded
encoded
w/ key=k
as Caesar
(n modw/ i → I1+: ki(n→
m) :key=k I +m)k(mod
mod 1 (mod
26)
26)
2nd natural
Decryption: In the encoded as Caesar w/ key=k2 : i → I + k2 (mod 26)
letterway
…
Important Property: Can no longer break using letter frequencies alone.
mth letter encoded as Caesar w/ key=km : i → I + km (mod 26)
‘e’ will be mapped to ‘e’+k1,‘e’+k2,…,‘e’+km according to location.
m+1th letter encoded as Caesar w/ key=k1 : i → I + k1 (mod 26)
Considered “unbreakable” for 300 years (broken by Babbage, Kasiski 1850’s)
48
48
24
12/2/2023
Vigenere Cipher
49
49
50
50
25
12/2/2023
Encryption: nth letter encoded w/ key=k(n mod m) : i → I + k(n mod m) (mod 26)
Decryption: In the natural way
Breaking Vigenere:
LIVITCSWPIYVEWHEVSRIQMXLEYVEOIEWHRXEXIPFEM VEWHKV
51
51
Encryption: nth letter encoded w/ key=k(n mod m) : i → i + k(n mod m) (mod 26)
Decryption: In the natural way
Breaking Vigenere:
LIVITC
SWPIYV
EWHEVS Step 1: Guess the length of the key m
RIQMXL
EYVEOI Step 2: Group together positions 1, m+1, 2m+1, 3m+1,…
EWHRXE
XIPFEM {2, m+2, 2m+2, 3m+2,…}
VEWHKV …
{m-1, 2m+m-1, 3m+m-1,…}
52
52
26
12/2/2023
Frequency analysis
53
53
54
54
27
12/2/2023
55
55
❑ Look at the 1st , 6th ,11th , … …. letters and see which letter occurs most
frequently.
In our example we obtain :
56
56
28
12/2/2023
❑ Look at the 3rd , 8th ,13th , ……. letters and see which letter occurs most frequently.
As in the first and second guess the third element of the key is 3 = d
57
57
58
58
29
12/2/2023
59
59
60
60
30
12/2/2023
61
61
62
31
12/2/2023
Transposition Ciphers
63
63
❑ EX. :
Plaintext: Meet me after the toga party
NO. of rows 2
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
64
64
32
12/2/2023
65
65
Double Transposition
Plaintext: attackxatxdawn
Permute rows
and columns
Ciphertext: xtawxnattxadakc
Key: matrix size and permutations (3,5,1,4,2)
and (1,3,2)
66
33
12/2/2023
ADFGX ciphers
A D F G X • Why ADFGX?
– Morse code for these are very
different
A l k p b q – Combined cryptography with
error-correction
D m v r t z • Matrix 1:
– 25 letters (i and j merged
F e f o d g again) randomly placed
• Each plaintext letter
G x c i y n replaced by its row and
column labels
X h u w a s • hello there →
• XA FA AA AA FF DG XA FA DF FA
67
• XA FA AA AA FF DG XA FA
DF FA C R Y P T U
• Matrix 2: pick a random
keyword and write the X A F A A A
previous result under it in
scanline order. A A F F D G
• Shuffle the columns into
alphabetical order X A F A D F
• Then read down the
columns F A
68
34
12/2/2023
• XA FA AA AA DG FF XA
FA DF FA
• Matrix 2: pick a random
keyword and write the C P R T U Y
previous result under it
in scanline order. X A A A A F
• Shuffle the columns
into alphabetical order
• Then read down the
A F A D G F
columns to get
ciphertext: X A A D F F
• XAXFAFAAAAAADDAGF F A
FFF
69
70
35
12/2/2023
Enigma
• To encrypt
– Press plaintext
letter, ciphertext
lights up
• To decrypt
– Press ciphertext
letter, plaintext
lights up
• Electo-mechanical
71
Enigma Crypto
Features
• 3 rotors
– Set initial positions
• Moveable ring on rotor
– Odometer effect
• Stecker (plugboard)
– Connect pairs of
letters
• Reflector
– Static “rotor”
72
36
12/2/2023
Enigma is a substitution
cipher
Enigma is an example of a
poly-alphabetic substitution
73
Three rotors
http://enigmaco.de/enigma/enigma.swf
74
37
12/2/2023
75
0 xor 0 = 0
Basic operation – bitwise
XOR
0 xor 1 = 1
XOR table
1 xor 0 = 1
One-Time Pad
Plain text is represented as
bit stream
1 xor 1 = 0
Key is random bit stream of
same length
76
38
12/2/2023
77
78
39
12/2/2023
79
80
40
12/2/2023
Key
• Sheets on pad must match exactly
coordination • Messages must arrive in order sent
problem
One-Time Pad– Why
Look Elsewhere?
Key
• High quality random numbers hard to
generation generate
problem
Bottom line
– has some
limited use
81
Advantages of One-Time
Pad
slide
82
82
41
12/2/2023
Insecure
• Attacker can obtain XOR of
if keys are plaintexts
reused
slide
83
83
slide 84
84
42
12/2/2023
Cryptanalytic Attacks
May be classified by how much information needed by the attacker:
– Ciphertext-only attack
– Known-plaintext attack
– Chosen-plaintext attack
– Chosen-ciphertext attack
Cryptanalysis
Non-brute-force brute-force
85
85
Ciphertext-only attack
• Given: a ciphertext c
• Q: what is the plaintext m?
• An encryption scheme is completely insecure if
it cannot resist ciphertext-only attacks.
86
43
12/2/2023
Known-plaintext attack
87
Chosen-plaintext attack
• Given: (m1,c1), (m2,c2), …, (mk,ck), where m1, m2, …, mk are chosen
by the adversary; and a new ciphertext c.
• Q: what is the plaintext of c, or what is the secret key?
88
44
12/2/2023
Example:
Pentagon didn’t think so.
chosen-
plaintext US forces in Midway sent a plain message
that their freshwater supplies were low.
89
89
Chosen-ciphertext attack
• Given: (m1,c1), (m2,c2), …, (mk,ck), where c1, c2, …, ck are chosen by
the adversary; and a new ciphertext c.
• Q: what is the plaintext of c, or what is the secret key?
90
45
12/2/2023
classified as
Active attacks
91
91
Passive Attacks
• Reading contents of messages
• Also called eavesdropping
• Difficult to detect passive attacks
• Defense: to prevent their success
92
92
46
12/2/2023
Active Attacks
• Modification or creation of messages
(by attackers)
• Four categories: modification of
messages, replay, masquerade, denial
of service
• Easy to detect but difficult to prevent
• Defense: detect attacks and recover
from damages
93
93
Active Attacks
94
94
47
12/2/2023
Active Attacks
95
95
Active Attacks
96
96
48
12/2/2023
97
97
Frequency analysis
98
98
49