Introduction to Cryptography Course
Introduction to Cryptography Course
MODULE: Cryptography
This course is an introduction to cryptography. It allows you to acquire the
theoretical knowledge necessary for a good understanding of the
cryptography. This knowledge allows for the protection of messages in order to
CRYPTOGRAPHY better secure information systems.
Evaluation
Written exam: 70%
Projet : 30%
Program
I. Introduction: Basic notions of cryptography (history, encryption and
decryption, cryptanalysis, qualities of a cryptosystem, ...
II. Ancient Cryptography
Introduction
2. Transposition Cipher
3. Substitution cipher
III. Modern Cryptography
4. Asymmetric encryption
5. Symmetric encryption
Project: Programming an encryption algorithm
3
1
Cryptography - Pr Aziz Ifzarne
7 8
2
Cryptography - Pr Aziz Ifzarne
9 10
11 12
3
Cryptography - Pr Aziz Ifzarne
15 16
4
Cryptography - Professor Aziz Ifzarne
17 18
Encryption
PART 1 by transposition
CRYPTOGRAPHY
Grid method
ANCIENT
5
Cryptography - Pr Aziz Ifzarne
He reads the text in columns and thus obtains the encrypted message:
R□D□VAEVEMINNOMILEDUADLUESIIESZ□N□TE
21 22
23 24
6
Cryptography - Pr Aziz Ifzarne
Substitution encryption
It involves replacing the characters of the clear text with other characters.
Encryption The most common encryptions:
by substitution
Substitution monoalphabetic: consists of replacing each letter of the
message through another letter (Example: Caesar code, affine code)
26
Why arithmetic?
arithmetic is at the heart of message encryption. To encrypt a message
we start by transforming it into numbers.
The process of encoding and decoding can involve several concepts.
Reminders of arithmetic:
Modular arithmetic Calculations in Z/nZ
Prime numbers and the decomposition into prime factors
Fundamental theorems such as Fermat's little theorem.
28
7
Cryptography - Professor Aziz Ifzarne
29 30
Modular arithmetic
Exercise
In Z/nZ, we can define addition and multiplication:
1) Calculate2018 in Z/7Z.
̅+ = + .̅ = .
2) Calculate213+ 17and213 − 17 in Z/7Z.
(Z/nZ; +, .) is a commutative ring.
3) Tracer la table de multiplication modulo 7 (Z/7Z)
Example. Addition and multiplication tables in Z/4 Z.
31 32
8
Cryptographie - Pr Aziz Ifzarne
Caesar Cipher
It is easier to manipulate numbers than letters.
To code, we replace each letter with its rank in the alphabet.
A=1, B=2, C=3,....,M=13, N=14,...,S=20,...,X=24, Y=25, Z=26
We are dealing with a monoalphabetic substitution code with a secret key. Julius Caesar
Substitution mono-alphabetic During the Gallic War, Julius Caesar used the following substitution code:
coded letter = clear letter shifted by 3
Caesar cipher Mathematically, this is written as:
encoded letter = clear letter + 3 modulo 26
The plaintext message
MEET TOMORROW AT NOON IN VILLETANEUSE
becomes
UHQGHC YRXV GHPDLQ PLGL YLOOHWDQHXVH
34
35 36
9
Cryptography - Professor Aziz Ifzarne
Use the MOD function in Excel: and since -13 ≡ 13 (mod 26) then D13(x) = x + 13.
MOD(x;y) returns the remainder of the division of x by y. The decryption function is the same as the encryption function!
37 38
It is clear that this Caesar cipher has very weak security. To encrypt the message
If Linda sends a secret message to Sara and Farid intercepts that message, he TO BE OR NOT TO BE THAT IS THE QUESTION
it will be easy for him to decrypt it even if he does not know the secret key.
The simplest attack for Farid is to test what each of the 26 produces. we look at the correspondence and replace the letter E with the letter X, then the
possible combinations and to recognize among these combinations which one letter T by letter G,..
give a comprehensible message. The encrypted message is then:
THIS IS AN EXAMPLE OF ENCRYPTED TEXT
39 40
10
Cryptography - Pr Aziz Ifzarne
Mathematically, there are 26! possible keys. This amounts to about 4 x10 keys. The main weakness of monoalphabetic encryption is that the same
The letter is always encrypted in the same way.
There are more different keys than grains of sand on Earth!
A cryptanalysis technique used to attack an encryption by
If a computer could test 1,000,000 keys per second, it would then take substitution mono-alphabetical relies on frequency analysis of
12 million years to list everything. symbols used in the encrypted text. It uses the fact that, in every language,
certain symbols or combinations of symbols appear more
more frequently than others.
If the encrypted message is long enough, the search for a symbol having
A high frequency will sometimes allow you to recover all or part of the message.
clear associated.
In French, the most commonly encountered letters are in the order:
ESAINTRULODCPMVQGFHBXJYZKW
41 42
43 44
11
Cryptography - Pr Aziz Ifzarne
45
47 48
12
Cryptography - Pr Aziz Ifzarne
50
51 52
13
Cryptography - Prof. Aziz Ifzarne
53 54
Exercise 1: Encryption
With the Vigenère code, encrypt the text 'SECRET' with the key
TOP
Substitution poly-alphabetic
Exercise 2: Decryption
Hill cipher
Decode the following text by hand using the Vigenère cipher.
utilisant le mot-clef «BIEN » (équivalent numérique 1 8 4 13):
CZEIP
55
14
Cryptography - Pr Aziz Ifzarne
Reminder:
Determiner
Inverse of a matrix
58
59 60
15
Cryptography - Pr Aziz Ifzarne
The sign (-1)i+j can be quickly evaluated starting from square a11with a
sign + and by switching to the opposite sign each time when moving by one
61 move horizontally or vertically to the a squareij. 62
63 64
16
Cryptography - Pr Aziz Ifzarne
65 66
67 68
17
Cryptography - Pr Aziz Ifzarne
Hill Cipher
On décrit maintenant un autre système cryptographique appelé chiffrement de Hill. Ce chiffre Case m=2: Encryption
published in 1929 by Lester S. Hill (1891-1961) is polyalphabetic.
The idea is to transform m characters from a block of clear text into m characters of a block
of text encrypted by linear combinations.
We take a square matrix of size mxm as key K.
For x = (x1; … ; xm) a block of clear text in m characters and y = C(x) = (y1; …. ; ymthe block of
encrypted text, we have:
69 70
Decryption
Conditions for application of the code
A matrix K with coefficients in Z/nZ is invertible.
if and only if its determinant is invertible modulo n,
That is to say, gcd(det K; n) = 1.
In our case, for the matrix K to be invertible modulo 26, we must have
gcd(det K, 26) = 1, that is to say, det K and 26 are coprime (do not have
the positive common divisor other than 1.
Otherwise, it is necessary to check that (ad–bc) is odd and not a multiple of 13.
71 72
18
Cryptography - Pr Aziz Ifzarne
Encryption
Example Each letter is replaced by its rank. Then we encode the message:
THIS IS A TEST
Using a matrix whose determinant is coprime with 26, we seek to
encrypt the following message: We group the letters in pairs, thus creating 7 vectors of dimension two, the last pair being
arbitrarily completed:
TEXTENCRYPT
We take:
We then multiply these vectors by matrix A while working on congruences modulo 26:
whose determinant is 21. Since 5 × 21 = 105 ≡ 1 (mod 26), 5 is an inverse We then obtain 7 vectors, or 14 letters. The first vector is (25; 0). The first two letters
the det(A) modulo 26. encoded are therefore "ZA".
Question: Find the entire encrypted text. How can we decrypt this text?
73 74
75 76
19
Cryptography - Pr Aziz Ifzarne
PREPARE TO NEGOTIATE
79 80
20
Cryptography - Professor Aziz Ifzarne
81 82
Encrypt then decrypt the message 'NOT TOMORROW' using the following coding matrix: PART2
CRYPTOGRAPHY
MODERN
We assign a number to each letter of the alphabet:
A = 1, B = 2, … , Z = 26; Space between two words = 27
83
21
Cryptography - Pr Aziz Ifzarne
85
87 88
22
Cryptography - Pr Aziz Ifzarne
89 90
The key must be a string of characters at least as long as the message to be encrypted.
THE DISPOSABLE MASK Each key, or "mask", should only be used once (hence the name mask.
disposable).
92
23
Cryptography - Pr Aziz Ifzarne
93 94
Encryption Decryption
We want to encrypt the message 'HELLO'. To do this, we assign a number (by It is done in a similar way, except that the mask is subtracted from the text.
example from 0 to 25) to each letter. Then we add the value of each encrypted instead of summing it. Here again, we may add 26 to the
letter with the corresponding value in the mask (modulo 26 calculation): result to obtain numbers between 0 and 25:
HELLO 3 (D) 16 (Q) 13 (N) 21 (V) 25 (Z) encrypted message
+ 22 (W) 12 (M) 2 (C) 10 (K) 11 (L) mask
- 22 (W) 12 (M) 2 (C) 10 (K) 11 (L) mask
29 16 13 21 25 mask + message
-19 4 11 11 14 encrypted message - mask
= 3 (D) 16 (Q) 13 (N) 21 (V) 25 (Z) mask + message mod 26
HELLO encrypted message - modulo 26 mask
The initial message 'HELLO' is indeed found.
The text received by the recipient is 'DQNVZ'.
95 96
24
Cryptography - Pr Aziz Ifzarne
Call A a bit of the clear and B the bit of the same rank of the key. Encryption consists of calculating
a bit C by performing the exclusive OR function, noted XOR (eXclusive OR), on A and B. This is
defined by the following table, which indicates for all possible values of A and B the value of
result, which we denote A⊕ B :
A B C = A⊕ B
0 0 0
0 1 1
1 0 1
1 1 0
97 98
99 100
25
Cryptography - Pr Aziz Ifzarne
101 102
Exercises Exercises
Exercise 1. Exercise 2.
Avec le code de Vernam, déchiffrer le mot « SSXHMAZCUA » en utilisant la clé "SHRTVSGVIW". Encrypt the message 'SOS' using the one-time pad method, going through binary code
(See the ASCII table below) and using the XOR operator. Take 'YEN' as the key.
How do we find the plaintext? Justify your answer.
Decipher the message.
103 104
26
Cryptography - Prof. Aziz Ifzarne
DES is a symmetric encryption developed in the 1970s by IBM. The DES method was
adopted and made standard by the United States government. It uses keys of a size of
Symmetric cryptography
56 bits which makes it easy to break today with new cryptanalysis technologies.
Principle of the algorithm
DES & AES The algorithm uses a 56-bit key. The number of keys is:
2^56=72,057,595,037,927,936
The plaintext is divided into blocks of 64 bits that will be encrypted one by one.
The algorithm is based on easy operations (a total of 19 steps) to be performed by a processor.
Offset;
— "or exclusive" ;
Transposition/copying
106
107 108
27
Cryptography - Pr Aziz Ifzarne
AES: cryptanalysis
109
28
Cryptography - Pr Aziz Ifzarne
Let a∈Z and b∈N*. There exists a unique pair (q,r)∈Z2such as:
a = bq + r and 0 ≤ r < b.
113 114
Example
6 and 35 are coprime.
115 116
29
Cryptographie - Pr Aziz Ifzarne
117 118
Example Exercise
Let's calculate the Bézout coefficients for a = 600 and b = 124. The left part is the algorithm.
of Euclid. The straight part is obtained from bottom to top.
Calculate the Bézout coefficients of 50 and 17.
119 120
30
Cryptography - Pr Aziz Ifzarne
123 124
31
Cryptography - Pr Aziz Ifzarne
125 126
127 128
32
Cryptography - Pr Aziz Ifzarne
129 130
Modular exponentiation
The naive calculation of modular exponentiation mod n is as follows:
the number is multiplied by itself multiple times, and once by the integer beobtained, we calculate its
remaining modular of the Euclidean division algorithm.
However, this method is not practical for large numbers. The exponential
quick modular drastically reduces both the number of operations and the space in
memory required for the execution of modular exponentiation.
132
33
Cryptography - Pr Aziz Ifzarne
In this notation, the length of the string is in [Link] take the value 0 or 1
for all titles that 0 ≤ i < n - 1. By definition, an1= 1.
133 134
135 136
34
Cryptography - Pr Aziz Ifzarne
137 138
Difficult
139 140
35
Cryptography - Pr Aziz Ifzarne
141 142
143 144
36
Cryptography - Pr Aziz Ifzarne
145 146
37
Cryptography - Pr Aziz Ifzarne
TD - RSAEncryption
Quantum alternative? Exercise 1. (Extended Euclidean Algorithm)
1) Using Euclid's algorithm, calculate the GCD of 120 and 23.
Peter Shor (1994): With a quantum computer, one can
efficiently factor integers (response time 2) With the extended Euclidean algorithm, deduce the coefficients of
Bézout (two integers such that 120u + 23v = GCD(120, 23))
polynomial).
3) Deduce the inverse of 23 modulo 120.
Security experts estimated several dozens
years required for a quantum computer to
to break a 2048-bit RSA encryption, and have developed Exercise 2. (Modular exponentiation)
of encryptions that even a quantum computer does not Calculate 15617mod 437
will not be able to crack.
Calculate 5144721mod 17
149 150
Exercise 4.
The exchange algorithm
1) Let's take p = 29; q = 31 and e = 13: Use the RSA protocol to
Diffie-Hellman keys
encrypt and decrypt M = 123.
2) Same question for p = 47; q = 59 and e = 17.
151
38
Cryptography - Pr Aziz Ifzarne
153 154
155 156
39
Cryptography - Pr Aziz Ifzarne
157 158
159 160
40
Cryptography - Prof. Aziz Ifzarne
161 162
Confidentiality Applications
Confidentiality is guaranteed by the fact that a potential attacker, who The Diffie-Hellman algorithm is a key exchange algorithm,
would intercept the communications between Alice and Bob, would have no way to used notably when opening a connection to a site
retrieve the private key from the information transmitted publicly. secured via the SSL/TLS protocol.
At the end of the protocol, Alice and Bob are therefore in possession of the same key.
secret K, which they did not exchange directly. If someone has spied on their It is also used for matching problems of two
conversations, he knows p, a, y1 and y2. He cannot find K as they do. objects in Bluetooth technology.
Alice or Bob. x1 and x2 being very large numbers, it is indeed extremely
difficult to retrieve their values from the information transmitted in plain text
(discrete logarithm problem).
163 164
41
Cryptographie - Pr Aziz Ifzarne
166
FUNCTION
To overcome this flaw, one resorts to hybrid cryptography that combines the two.
systems in order to take advantage of the benefits (speed of symmetric cryptography
for the content of the message) and use of 'slow' cryptography
HASHING
only for the key.
In many modern communication environments, including
Internet, most of the exchanged data is encrypted by the symmetric algorithm
fast AES. Its private key, called the session key, is encrypted with the algorithm
asymmetric RSA.
Private key code: Encryption and decryption of the message
Public key: Encryption and decryption of the key
167
42
Cryptography - Prof. Aziz Ifzarne
169 170
171 172
43
Cryptography - Pr Aziz Ifzarne
Digital signature
Digital signature (or electronic signature) is a mechanism
ensuring the integrity of an electronic document and
to authenticate the author, by analogy with the handwritten signature of a
paper document.
The signature is obtained by first applying a hash function to the
then encrypt the summary using a key (private or public).
Hashing Encryption
Document ----------------> Résumé ------------------> Signature
173
44