Lecturenotes
Lecturenotes
Rabah Djabri
University of Bejaia
Department of Operations Research
Introduction 2
1 Mathematical preliminaries 4
1.1 Sets and maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2 Number theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.3 Euclidean algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.4 Least common multiple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.5 Fundamental theorem of arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.6 Modular arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.7 Arithmetic functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.8 Floor and ceiling functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2 Fundamental notions 21
2.1 Cryptosystems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3 Symmetric-key encryption 23
3.1 Caesar cipher or shift cipher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.2 Affine cipher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.3 Vigenère cipher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.4 Hill cipher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.5 Affine Hill cipher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.6 Modern symmetric-key ciphers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.7 Feistel Cipher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.8 Data Encryption Standard Cipher DES . . . . . . . . . . . . . . . . . . . . . . . 25
3.9 Advanced Encryption Standard AES . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.10 Modes of operation of bloc ciphers . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4 Asymmetric-key encryption 28
4.1 RSA cryptosystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4.2 Diffie-Hellman key exchange . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4.3 ElGamal cryptosystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
5 Digital signatures 30
5.1 Hash functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
5.2 RSA digital signature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
5.3 ElGamal digital signature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
5.4 Digital Signature Algorithm DSA . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
1
A Appendix 33
A.1 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
A.2 Tests and exams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
A.3 List of notations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
A.4 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
2
Introduction
Aims : The aim of this course is to present the fundamentals of cryptography and explore its
importance in different areas of modern life: E-commerce, telecommunications, information tech-
nology, computer science, bank transactions, etc.
Prerequisites: linear algebra, probability theory, elementary notions of number theory
Content:
History: permutation cipher, substitution cipher (Caesar cipher), Vigenère cipher, Hill cipher,
Fundamental notions : cryptosystem, plaintext, code, encryption function, decryption function,
key, digital certificate, hash function, security, confidentiality, authentication, data integrity,
non-repudiation, signature verification, digital signature cryptogram, encryption algorithm, en-
cryption, decryption
Encryption methods
Symmetric-key and asymmetric-key encryption
Modern codes: DES, AES, DSA, RSA
3
Chapter 1
Mathematical preliminaries
A ∩ B = {x : x ∈ A ∧ x ∈ B}.
If we have an
T arbitrary T
family of sets {Aα : α ∈ I} indexed by a set I, then their intersection
denoted by α∈I Aα or {Aα : α ∈ I}, is given by
\
Aα = {x : (∀α ∈ I)(x ∈ Aα )}.
α∈I
A ∪ B = {x : x ∈ A ∨ x ∈ B}.
If we
S have an arbitrary family of sets {Aα : α ∈ I} indexed by a set I, then their union denoted
by α∈I Aα or {Aα : α ∈ I}, is given by
S
[
Aα = {x : (∃α ∈ I)(x ∈ Aα )}.
α∈I
A − B = {x : x ∈ A ∧ x ∈
/ B}.
Ac = {x : x ∈ X ∧ x ∈
/ A}.
4
We say that a set A is included in the set B, which is denoted by A ⊆ B if
(∀x)(x ∈ A =⇒ x ∈ B).
A = B ⇐⇒ A ⊆ B ∧ B ⊆ A.
P(X) = {S : S ⊆ X}.
If we have a sequence of sets (An )n≥1 , then its limit inferior is defined by
∞ \
[ ∞
lim inf An = Ai ,
n=1 i=n
If we have a real sequence (xn )n≥1 , then its limit inferior is defined by
5
• A ⊆ B, then sup A ≤ sup B,
• sup A = − inf −A,
• sup(A ∪ B) = max(sup A, sup B),
• sup(A ∪ B) = sup A + sup B − min(sup A, sup B),
• inf(A ∪ B) = inf A + inf B − max(inf A, inf B),
• lim sup xn = − lim inf −xn .
Proposition 1.2. We have :
• ∨(A ∪ B) = ∨{∨(A), ∨(B)} (∨ is associative),
• ∧(A ∪ B) = ∧{∧(A), ∧(B)} (∨ is associative),
• (a ∧ b)c = (ac) ∧ (bc) ( c ≥ 0),
• (a ∨ b)c = (ac) ∨ (bc) ( c ≥ 0),
• (a ∧ b) ∨ c = (a ∨ c) ∧ (b ∨ c),
• (a ∨ b) ∧ c = (a ∧ c) ∨ (b ∧ c),
• |a| = (−a) ∨ a.
Let f : X → Y be map. The set X is called the domain of f , and Y is called the codomain of f .
If f (x) = y, then y is the image of x by the function f , and x is a preimage of y by the function
f . The image of a subset A of X by the map f , denoted by f (A), is given by
The inverse image (or the preimage) of a subset B of Y , denoted by f −1 (B), is given by
A × B = {(a, b) : a ∈ A, b ∈ B},
Y
Aα = {(aα )α∈I : (∀α ∈ I)(aα ∈ Aα )} .
α∈I
6
6. A ⊆ f −1 [f (A)].
Proposition 1.4. We have the following:
1. A ( α∈I Bα ) = α∈I (A Bα ),
TS S T
2. A ( α∈I Bα ) = α∈I (A Bα ),
ST T S
We denote by muℓ(a) the set of multiples of the integer a, i.e. muℓ(a) = aZ.
We denote by muℓ(a1 , a2 , . . . , an ) the set of common multiples of a1 , a2 , . . . , an , i.e.
n
\
muℓ(a1 , a2 , . . . , an ) = muℓ(ai ).
i=1
N = {0, 1, 2, . . . }.
Z = {. . . , −2, −1, 0, 1, 2, . . . }.
Z+ = N = {0, 1, 2, . . . }.
2Z = {2n : n ∈ Z}.
7
The set of odd integers which is denoted by 2Z + 1 is given by
2Z + 1 = {2n + 1 : n ∈ Z}.
C = {x + iy : x, y ∈ R}
Theorem 1.1 (The division algorithm). Let a and b be integers with b > 0, then there exist
unique integers q, r such that
a = qb + r
with 0 ≤ r < b. The integer q is called the quotient and r is the remainder of the division.
Let R : Z × N∗ → N be the map given by
R(a, b) = r
8
Lemma 1.1. Suppose that a and b are integers such that a = qb + r. Then gcd(a, b) = gcd(b, r).
Let a and b be integers such that b > 0. Set r0 = a and r1 = b. Then there is a unique
natural number N ≥ 0 and natural numbers (r0 , r1 , . . . , rN , rN +1 = 0) with r0 , r1 , . . . , rN ≥ 1
such that:
And hence
rN −1 = qN rN + 0 with rN +1 = 0.
We get (r0 , r1 , . . . ) or (ri )i∈I where I = {0, 1, . . . , n} for some n ∈ N∗ or I = N
The last term in the sequence is 0 if it is finite. We have to prove that every sequence is finite,
that is the algorithm will stop after a finite number of steps. By induction we have ri ≤ b. The
remainder rN is the last non-zero remainder of the division algorithm. Therefore we have
Therefore
gcd(a, b) = rN and div(a, b) = div(rN , 0) = div gcd(a, b).
Algorithm 1.1 (The Euclidean algorithm).
Input : non-negative integers a, b, with b > 0
Output : gcd(a, b)
1. Compute R(a, b)
2. If R(a, b) = 0 go to (3) otherwise go to (4)
3. Write gcd = b and stop
4. Do a ← b and b ← R(a, b) and go to (1)
Theorem 1.2 (The extended Euclidean algorithm).
Let r0 = a, r1 = b, (α0 , β0 ) = (1, 0), (α1 , β1 ) = (0, 1). Suppose that RN the last non-zero
remainder of the division algorithm of a by b. Hence
Define
αi+2 = −qi+1 αi+1 + αi and βi+2 = −qi+1 βi+1 + βi .
That is
(αi+2 , βi+2 ) = −qi+1 (αi+1 , βi+1 ) + (αi , βi ).
Therefore we get
r0 αi + r1 βi = ri for i = 0, . . . , N.
Hence
r0 αN + r1 βN = rN .
That is
aαN + bβN = gcd(a, b).
Theorem 1.3 (Bézout’s theorem). Let a and b be integers not both zero and d = gcd(a, b).
Then
9
1. there exist integers x and y such that ax + by = d.
2. and div(a, b) = div(d).
3. and {ax + by : x, y ∈ Z} = dZ, that is aZ + bZ = (a ∧ b)Z.
Proof.
1. Let
S = {ax + by : ax + by > 0, x, y ∈ Z}
Since the set S is a subset of the natural numbers and S is not empty, then S has a smallest
element, say s (hence s = ax0 + by0 for some integers x0 and y0 ).
Let R(a, s) = r, that is a = qs + r with 0 ≤ r < s. We have r = a − qs = a(1 − qx0 ) − by0 .
If r > 0, then r ∈ S. And since r < s, this contradicts thet fact that s is the smallest
element of S. Therefore r = 0, and hence s ∈ div(a). In the same manner we prove that
s ∈ div(b). Therefore
s ∈ div(a, b).
Since d divides both a and b, then d divides ax0 + by0 = s. Therefore s = d, and hence
ax0 + by0 = d
2. Since h divides both a and b, then h divides ax0 + by0 = d. Therefore h ∈ div(d). If
h ∈ div(d), then h ∈ div(a, b) since d divides both a and b. Therefore
div(a, b) = div(d).
3. Since ax0 + by0 = d, then a(αx0 ) + b(αy0 ) = dα for any integer α. Thus we have (a ∧ b)Z ⊆
aZ+bZ. On the other hand suppose that ax+by = t, then ax+by = qd+r = qax0 +qby0 +r
with 0 ≤ r < d. Hence r = a(x − qx0 ) + b(y − qy0 ), and if r ̸= 0 then r would be in S
which contradicts the fact that d is the smallest element of S. Hence r = 0 and therefore
t = qd. Hence aZ + bZ ⊆ (a ∧ b)Z. Hence
aZ + bZ = (a ∧ b)Z.
We have the following generalization of the preceding theorem. The proof is almost identical
to the proof of the preceding theorem.
Theorem 1.4. Let a1 , a2 , . . . , an be integers not all zero, and d = gcd(a1 , a2 , . . . , an ). Then
Pn
1. there exist integers x1 , x2 , . . . , xn such that i=1 ai xi = d.
2. and div(a1 , a2 , . . . , an ) = div(d).
Pn Pn
3. and { i=1 ai xi : x1 , x2 , . . . , xn ∈ Z} = dZ, that is i ai Z = (∧i ai )Z.
Definition 1.4. Let a and b be integers not both zero. Then we say that a and b are relatively
prime (or coprime) if gcd(a, b) = 1.
Proposition 1.6. We have
1. aZ = bZ if and only if |a| = |b| (a, b are integers).
10
2. If ax + by = 1, then gcd(a, b) = 1.
3. If gcd(a, b) = d, then gcd ad , db = 1.
1. We have 1 = ax + by = gcd(a, b)α for some integer α by the previous theorem. Hence
gcd(a, b) = 1.
2. We have aZ + bZ = dZ. Hence ad Z + db Z = Z = gcd ad , dd Z. Therefore
gcd ad , dd = 1.
3. We have
(a ∧ b ∧ c)Z = aZ + bZ + cZ
= (aZ + bZ) + cZ
= (a ∧ b)Z + cZ
= ((a ∧ b) ∧ c)Z.
On the other hand we have
(a ∧ b ∧ c)Z = aZ + bZ + cZ
= aZ + (bZ + cZ)
= aZ + (b ∧ c)Z
= (a ∧ (b ∧ c))Z.
Hence
(a ∧ b) ∧ c = a ∧ (b ∧ c) = a ∧ b ∧ c.
4. We have
(a ∨ b ∨ c)Z = aZ ∩ bZ ∩ cZ
= (aZ ∩ bZ) ∩ cZ
= (a ∨ b)Z ∩ cZ
= ((a ∨ b) ∨ c)Z.
On the other hand we have
(a ∨ b ∨ c)Z = aZ ∩ bZ ∩ cZ
= aZ ∩ (bZ ∩ cZ)
= aZ ∩ (b ∨ c)Z
= (a ∨ (b ∨ c))Z.
Hence
(a ∨ b) ∨ c = a ∨ (b ∧ c) = a ∨ b ∨ c.
11
5. We have
Therefore
(a1 ∧ a2 ∧ · · · ∧ am ) ∧ (b1 ∧ b2 ∧ · · · ∧ bn ) = a1 ∧ a2 ∧ · · · ∧ am ∧ b1 ∧ b2 ∧ · · · ∧ bn .
6. We have
Therefore
(a1 ∨ a2 ∨ · · · ∨ am ) ∨ (b1 ∨ b2 ∨ · · · ∨ bn ) = a1 ∨ a2 ∨ · · · ∨ am ∨ b1 ∨ b2 ∨ · · · ∨ bn .
Proof.
12
1. Let m = ℓcm(a, b), that is m = min(muℓ(a, b) ∩ N∗ ). For h ∈ muℓ(a, b), let h = qm + r
with 0 ≤ r < m. Then r = h − qm, and since h ∈ muℓ(a, b) and qm ∈ muℓ(a, b) therefore
r ∈ muℓ(a, b). If r ̸= 0 then would have r ∈ muℓ(a, b) ∩ N∗ which contradicts the fact that
m is the smallest element of muℓ(a, b) ∩ N∗ . Therefore r = 0 and hence h ∈ muℓ(m). On
the other hand if h ∈ muℓ(m) then h ∈ muℓ(a, b). Therefore
2. Let gcd(a, b) = d. We have abd muℓ(a, b), and hence d = αm for some integer α. Suppose
ab
Definition 1.6. An integer p > 1 is called a prime number if and only if its only positive divisors
are 1 and p.
√
Proposition 1.7. A number n ≥ 2 is not prime iff n is divisible by some
√ prime number p ≤ n.
A number n is prime iff n is not divisible by any prime number p ≤ n.
Proof. If the number n ≥ 2 is not prime, then there are primes p√and q and integer m such that
n = pqm. Suppose that p ≤ q. Hence p2 ≤ pqm = n. Hence p ≤ n.
Have
√
(n ≥ 2 and n ∈
/ Prm) ⇐⇒ (∃p)(p ∈ Prm and p ≤ n and p ∈ div(n))
13
1. Since gcd(a, b) = 1, then ax + by = 1 for some integers x and y. Hence acx + bcy = c. Since
a|acx and a|bcy, then a|acx + bcy = c. Hence a ∈ div(c).
2. If p ∈
/ div(a), then gcd(a, b) = 1. Then by the first part p ∈ div(b).
3. The proof is by induction.
Theorem 1.7 (The fundamental theorem of arithmetic). Every positive integer n > 1 can
be expressed uniquely up to order as a product of prime numbers.
Qm
Proposition 1.10. Let a = i=1 pα i and τ (a) be the number of positive divisors of a. Then
i
m
Y
τ (a) = (1 + αi ).
i=1
14
1.6 Modular arithmetic
Definition 1.7. We have the following definitions:
1. Let n be a positive integer. The integers a and b and are said to be congruent modulo n if
n divides a − b, and we write a ≡ b (mod n). We use the notation a ≡ b[n] as well.
2. Suppose that a ≡ b (mod n). Then we say that b is a residue of a modulo n. The residue
class of a modulo n is denoted by [a]n and is given by
3. For a positive integer n there are n distinct residue classes which are [0]n , [1]n , . . . , [n − 1]n .
4. Therefore we have [a]n = [b]n iff a ≡ b (mod n).
5. The relation ≡ is an equivalence relation, i.e. it is reflexive, symmetric and transitive.
6. The residue classes constitute a partition of Z, that is they are not empty, they are pairwise
disjoint and their union is Z.
7. The set of residue classes modulo n will be denote by Zn or Z/nZ, and we have
Zn = {a1 , a2 , . . . , an }.
11. We say that a set of integers {a1 , a2 , . . . , aφ(n) } is a reduced system of residues modulo n
iff
Z∗n = {a1 , a2 , . . . , aφ(n) }.
12. If {a1 , a2 , . . . , aφ(n) } is a reduced system of residues modulo n and gcd(α, n) = 1 then
{αa1 , αa2 , . . . , αaφ(n) } is a reduced system of residues modulo n.
Theorem 1.9. Let n be a positive integer and a, b and c arbitrary integers. Then the following
properties hold:
1. a ≡ a (mod n)
2. if a ≡ b (mod n), then b ≡ a (mod n)
3. if a ≡ b (mod n) and b ≡ c (mod n), then a ≡ c (mod n)
4. if a ≡ b (mod n) and c ≡ d (mod n), then a + c ≡ b + d (mod n)
5. if a ≡ b (mod n), then ac ≡ bc (mod n) and ak ≡ bk (mod n)
Proposition 1.11. Let n be a positive integer and a, b arbitrary integers. Then the following
properties hold:
15
1. If a ≡ b (mod n) then a mod n = b mod n
2. (a mod n + b mod n) mod n = (a + b) mod n
3. ((a mod n)(b mod n)) mod n = (ab) mod n
In other words φ(n) is the number of integers k with 1 ≤ k ≤ n such that k and n are
relatively prime.
5. We can see that φ(n) = card Z∗n the set of units of Zn .
that is
τ (mn) = τ (m)τ (n)
Proof. This can be shown by the bijection f : div+ (m) × div+ (n) → div+ (mn) given by
f (d1 , d2 ) = d1 d2 .
2. If gcd(m, n) = 1 then
σ(mn) = σ(m)σ(n)
16
Qk
3. If n = i=1 pαi
i , then
k
Y pαi +1 − 1
σ(n) = i
i=1
pi − 1
The map f is injective: Suppose that f ([a]mn ) = f ([b]mn ), that is ([a]m , [a]n ) = ([b]m , [b]n ),
hence b = a + αm and b = a + βn. Hence αm = βn, and since gcd(m, n) = 1 we find that
β = km and α = kn for some integer integer k. Therefore b = a + kmn, that is [a]mn = [b]mn .
The map f is surjective: Consider ([a]m , [b]n ) ∈ Z∗m ×Z∗n . Since gcd(m, n) = 1, then a+αm =
b+βn for some integers α and β. Let c = a+αm, and hence f ([c]mn ) = ([c]m , [c]n ) = ([a]m , [b]n ).
Therefore card Z∗mn = card Z∗m card Z∗n , that is φ(mn) = φ(m)φ(n).
Theorem 1.13. We have
Y 1
φ(n) = n 1− .
i
pi
Proof.
17
1. Let
S = {(α, d) : 1 ≤ α ≤ d, α ∧ d = 1, d ∈ div n}
Define the function f : S → {1, 2, . . . , n} by
αn
f (α, d) =
d
The function f is a bijection, and hence card S = n, i.e.
X
φ(d) = n
d∈div+ (n)
Theorem 1.14 (The Euler theorem). If a and n be positive integers such that gcd(a, n) = 1,
then
aφ(n) ≡ 1 (mod n).
Proof.
Consider Z∗n the set of units of Zn . Hence
Theorem 1.15 (The Fermat little theorem). If a is a positive integer and p a prime such
that gcd(a, p) = 1, then
ap−1 ≡ 1 (mod p).
Proof. We have φ(p) = p − 1. Apply the Euler theorem.
18
1.8 Floor and ceiling functions
1. The floor function ⌊·⌋ (the integer part): For a real number x the integer part of x is the
integer ⌊x⌋ such that
⌊x⌋ ≤ x < ⌊x⌋ + 1.
{x} = x − ⌊x⌋.
3. The ceiling function ⌈·⌉: For a real number x, the ceiling of x is the integer ⌈x⌉ such that
3. For x ∈ R
⌊x⌋ + ⌊−x⌋ = v(x ∈ Z) − 1.
7. For x, y ∈ R+
⌊x⌋⌊y⌋ ≤ ⌊xy⌋.
19
Proof. Let
S = N∗ ∩ [1, n], Si = muℓ pi ∩ [1, n], i ≥ 1.
We have
∅ ⊆ Sn ⊆ · · · ⊆ S2 ⊆ S1 .
Then
X
vp (n!) = vp (x)
x∈S
XX
= χSi (x)
x∈S i≥1
XX
= χSi (x)
i≥1 x∈S
X
= card Si
i≥1
X n
= .
pi
i≥1
Theorem 1.17 (The primitive root theorem). Consider Z∗p where p is a prime number.
Then there is an element g ∈ Z∗p that generates Z∗p (hence g is of order p − 1, it is called a
primitive root of Z∗p ).
Theorem 1.18 (The Cauchy theorem for groups). Let G be a finite group whose cardinality
is divisible by a prime number p. Then G has an element of order p.
20
Chapter 2
Fundamental notions
2.1 Cryptosystems
1. An alphabet is a nonempty set A.
2. We call the elements of A letters, or symbols.
3. A finite sequence of letters of A is called a word over A.
4. We write w = (w1 , w2 , . . . , wn ) or w = w1 , w2 . . . wn .
5. The empty word is denoted by ε.
6. If w = (w1 , w2 , . . . , wn ) is a word then the length of w is denoted by |w| and is given by
|w| = n. By definition |ε| = 0.
9. The concatenation of two words v and w is denoted by v ◦ w or vw, and is given by: if
v = (v1 , v2 , . . . , vm ) and w = (w1 , w2 , . . . , wn ), then
v ◦ w = (v1 , v2 , . . . , vm , w1 , w2 , . . . , wn )
and
ε ◦ w = w ◦ ε = w.
21
3. K is a set called the key space (the set of keys),
4. E = {ek : k ∈ K} is the space of encryption functions ek : P → C,
5. D = {dk : k ∈ K} is the space of decryption functions dk : P → C such that dk ◦ ek = idP .
2. Integrity
3. Authentication
4. Non-repudiation
22
Chapter 3
Symmetric-key encryption
ek (m) = m + k.
dk (c) = c − k.
Example 3.1. Consider the Caesar cipher given by P = C = K = Z26 representing the 26 letters
of the alphabet (A = 1, B = 2, . . . , Y = 25, Z = 0).
1. Given that k = 7, encrypt the letters A, F, X.
2. Encrypt the plaintext message SATURDAY.
3. Decrypt the ciphertext RLF.
The encryption function ek : Zd → Zd is given for k = (k1 , k2 ) ∈ Z∗d ×Zd (hence gcd(k1 , d) = 1)
by
ek (m) = k1 m + k2 .
The decryption function dk : Zd → Zd is given for c by
dk (c) = k1−1 (c − k2 ).
Example 3.2.
23
3.3 Vigenère cipher
A Vigenère cryptosystem (P, C, K, E, D) is given by P = C = Znd , K = Znd .
ek (m) = m + k.
dk (c) = c − k.
Example 3.3.
The encryption function ek : Znd → Znd is given for m and k ∈ GL(n, Zd ) (hence gcd(det k, d) =
1) by
ek (m) = km.
The decryption function dk : Znd → Znd is given by
dk (c) = k −1 c.
Example 3.4.
The encryption function ek : Znd → Znd is given for k = (k1 , k2 ) ∈ GL(n, Zd ) × Znd (hence
gcd(det k1 , d) = 1) by
ek (m) = k1 m + k2 .
The decryption function dk : Znd → Znd is given by
dk (c) = k1−1 (c − k2 ).
Example 3.5.
24
Algorithm 3.1 (The Feistel cipher).
4. The functions E, IP, Si , P, KS are fixed by the Standard (8 selection functions, or S-boxes).
5. Let k1 , k2 , . . . , k16 be the sub-keys corresponding to the rounds 1, 2, . . . , 16. Each sub-key
is a 48-bit block.
6. The keys ki are generated by ki = KS(i, k), i = 1, 2, . . . , 16 (KS is the key schedule
algorithm).
10. Get (R16 , L16 ) and the ciphertext block is c = IP−1 (R16 , L16 ).
11. To decrypt c get (R16 , L16 ) = IP(c) and let Ri−1 = Li and Li−1 = Ri ⊕ fki (Li ),
i = 16, 15, . . . , 1.
12. Get the plaintext block by m = IP−1 (L0 , R0 ).
25
We have Si : B6 → B4 is the i-th S-box (here B = {0, 1}).
Algorithm 3.3 (The key schedule algorithm).
fκ (R) = P [S1 (E(R) ⊕ κ)1 ∥S2 (E(R) ⊕ κ)2 ∥ . . . ∥S8 (E(R) ⊕ κ)8 ] .
26
(a) Given (mi )i≥0 , choose c−1 .
(b) Let ci = ek (mi ⊕ ci−1 ), i ≥ 0.
(c) Decrypt as mi = ci−1 ⊕ dk (ci ), i ≥ 0.
3. CFB: Cipher feedback mode
(a) Given (mi )i≥0 , and let c0 = ek (m0 ).
(b) Let ci = mi ⊕ ek (ci−1 ), i ≥ 1.
(c) Decrypt as mi = ci ⊕ ek (ci−1 ), i ≥ 1.
4. OFB: Output feedback mode
(a) Given (mi )i≥0 , choose an initial value s−1 .
(b) Let si = ek (si−1 ).
(c) Let ci = mi ⊕ si , i ≥ 0.
(d) Decrypt as mi = ci ⊕ si , i ≥ 0.
5. CTR: Counter mode
(a) Given (mi )i≥0 , choose an initial value T .
(b) Let si = ek (T + i).
(c) Let ci = mi ⊕ si , i ≥ 0.
(d) Decrypt as mi = ci ⊕ si , i ≥ 0.
6. PCBC: Propagating cipherblock chaining mode
CFB mode and OFB mode are examples of stream ciphers
CFB is self-synchronizing, OFB is synchronous
27
Chapter 4
Asymmetric-key encryption
28
a reasonable amount of time. The trapdoor information is some auxiliary information that can
be used to easily compute the inverse.
In a public-key cryptosystem a key k consists of two subkeys: a private key kpriv and a
public key kpub . Therefore k = (kpriv , kpub ). We say that kpriv is trapdoor information for the
encryption function ekpub , i.e. we are using kpriv to compute the inferse of ekpub .
29
Chapter 5
Digital signatures
The RSA algorithm can be used for encryption and for digital signatures as well. ElGamal is a
discrete logarithm based encryption. ElGamal digital signature scheme was introduced for the
first time in 1985. Then was modified in 1991 to get the version known as the Digital Signature
Algorithm (DSA) and published officially as the Digital Signature Standard (DSS) in 1994.
Definition 5.2. A hash function is H : B• → Bℓ for some fixed positive integer ℓ, given by
a polynomial algorithm. We say that H is collision resistant if it is infeasible to find a and b,
a ̸= b, such that H(a) = H(b).
30
5. She computes d the inverse of e modulo φ(n) with d < φ(n).
6. The ordered pair (n, e) is the public key.
7. Alice signs the document m by s = md mod n.
1. A large prime number p and a primitive root g in Z∗p are chosen by a public party.
2. Alice chooses a secret key a such that 1 ≤ a ≤ p − 1.
3. She computes A = g a mod p.
4. The verification key A is made public.
7. Bob computes As1 ss12 mod p and must verify that it is equal to g m mod p.
Proof. Proof of correctness:
We have
−1
(As1 ss12 ) mod p = g as1 (g k mod p)(m−as1 )k mod(p−1) mod p
−1
= g as1 +((m−as1 )kk mod(p−1)) mod p
= g as1 +(m−as1 )+α(p−1) mod p
= g m+α(p−1) mod p
= g m (g p−1 )α mod p
= (g m (1 + βp)α ) mod p
= g m mod p.
31
2. Alice chooses a secret key a such that 1 ≤ a ≤ q − 1.
3. She computes A = g a mod p.
4. The verification key A is made public.
= s1 .
32
Appendix A
Appendix
A.1 Exercises
University of Bejaia
Department of OR
Level: SDAD1
Course: Cryptography
Academic year: 22/23
Exercise 2.
33
Exercise 4.
1. Find according to the values of n the remainder of the division of 2n by 3.
2. Find according to the values of n the remainder of the division of 2n by 7.
2. 5x + 3 ≡ 11 (mod 12),
3. 14x ≡ 28 (mod 60).
Exercise 6. Use the Euclidean algorithm to find the inverse of a in Zn in the following cases:
1. a = 2, n = 5,
2. a = 5, n = 12,
3. a = 7, n = 30.
Supplementary exercises
Exercise 7. Solve the following congruences:
1. x + 7 ≡ 3 (mod 18),
2. 5x ≡ 12 (mod 100),
3. 5x ≡ 15 (mod 100),
4. x2 + 3 ≡ 2 (mod 5),
5. 4x ≡ 5 (mod 9),
6. 2x ≡ 7 (mod 17).
4. x2 ≡ 2 (mod 13),
5. x2 ≡ 1 (mod 8),
34
6. x3 − x2 + 2x − 2 ≡ 0 (mod 11),
7. x ≡ 1 (mod 5) and x ≡ 2 (mod 7),
8. x ≡ 3 (mod 7) and x ≡ 4 (mod 9),
9. x ≡ 4 (mod 7) and x ≡ 5 (mod 8) and x ≡ 11 (mod 15).
Exercise 12. Let A = [0, 2], B = [1, 3], C = [ 12 , 52 ], An = [−n + 1, n], Bn = [ n1 , 2], Cn = [0, n1 ].
1. Find : A ∪ B, A ∩ B, Ac .
S∞ S∞ T∞
2. Find : n=1 An , n=1 Bn , n=1 Cn .
g f
Exercise 13. Consider the the following maps: X → Y → Z. Show that
1. f −1 ( α∈I Aα ) = α∈I f −1 (Aα ),
S S
35
2. A ∪ ( Bα ) = α∈I (A ∪ Bα ).
T T
α∈I
g f
Exercise 15. Consider: X → Y → Z. Show that
1. f −1 (Ac ) = [f −1 (A)]c ,
36
University of Bejaia
Department of OR
Level: SDAD1
Module: Cryptography
Academic year: 23/24
Exercise 2. Consider the affine cipher given by P = C = Z26 , K = Z∗26 × Z26 , with Z26
representing the 26 letters of the alphabet (A = 1, B = 2, . . . , Y = 25, Z = 0).
1. Given that k = (7, 3), encrypt the plaintext message DAY.
2. Decrypt the ciphertext RLF.
3. Find the key if the letter S is encrypted to A, and the letter H to R.
Supplementary exercises
37
Exercise 5. Let n ∈ N∗ be a large positive integer and let M = C = K = Zn . For each k ∈ K
consider the function ek : M → C. Determine if K is a key space in the following cases:
1. ek (m) = k − m
2. ek (m) = km
3. ek (m) = (k + m)2
8 7 17
k = 19 x 4 .
20 1 4
Exercise 7. Consider the affine Hill cipher with Z7 and key k = (k1 , k2 ) given by
1 3
k1 = , and k2 = (5, 4)⊤ .
2 2
38
University of Bejaia
Department of OR
Level: SDAD1
Module: Cryptography
Academic year: 23/24
Exercise 3. Alice and Bob agree to use the prime p = 1373 and the base g = 2 for a
Diffie–Hellman key exchange. Alice sends Bob the value A = 974. Bob asks your assistance, so
you tell him to use the secret exponent b = 871.
1. Determine the value of B that Bob should send to Alice.
2. Determine their secret shared value.
Supplementary exercises
Exercise 4. Alice uses the RSA signature scheme with primes p = 541 and q = 1223 and public
verification exponent e = 159853.
1. Determine Alice’s public modulus.
2. Determine her private signing key.
3. Determine the signature of the digital document D = 630579 that Alice signs .
Exercise 5. Alice and Bob would like to agree on a secret key n such that 1 < n < 1000.
Both choose private keys: dA = 513 and dB = 33 modulo p = 1009, respectively. The smallest
primitive element modulo p is a = 11. Use the Diffie-Hellman key exchange to compute the
secret key for both Alice and Bob and show that they agree.
39
Solutions No. 1
Exercise 1.
We have as well
Therefore
(a ∧ b) ∧ c = max div(a, b ∧ c) = a ∧ b ∧ c.
2. We have
156 = 2 × 66 + 24
66 = 2 × 24 + 18
24 = 1 × 18 + 6
18 = 3 × 6 + 0.
Hence 156 ∧ 66 = 6.
We have
110 = 18 × 6 + 2
6 = 3 × 2 + 0.
Therefore we have
Exercise 2.
40
1. We have
17 = 1 × 12 + 5 → 5 = 17 − 1 × 12
12 = 2 × 5 + 2 → 2 = 12 − 2 × 5
5 = 2 × 2 + 1 → 1 = 5 − 2 × 2.
2. Since gcd(34, 24) = 2, then there are integers x0 and y0 such that 34x0 + 24y0 = 2. We
have
34 = 1 × 24 + 10 → 10 = 34 − 1 × 24
24 = 2 × 10 + 4 → 4 = 24 − 2 × 10
10 = 2 × 4 + 2 → 2 = 10 − 2 × 4
4 = 2 × 2 + 0.
34 × 5 + 24 × (−7) = 2 (A.1)
Therefore
34 × (5α + 24 × (−7α) = 2α (A.2)
Subtracting 34x+24y = 2α from 34×(5α+24×(−7α) = 2α we get 17(x−5α) = −12(7α+y).
Therefore (x, y) = (12s + 5α, −17s − 7α).
Supplementary exercises
Exercise 3. Let a = 163, b = 245 and c = 3675.
1. Prime factorization of the numbers a, b and c:
a = 163, b = 5 × 72 , c = 3 × 52 × 72 .
Hence gcd(a, b) = 30 ×50 ×70 ×1630 = 1 and ℓcm(a, b) = 30 ×51 ×72 ×1631 = 39935.
3. We have gcd(a, b, c) = 30 ×50 ×70 ×1630 = 1 and ℓcm(a, b, c) = 31 ×52 ×72 ×1631 =
599025.
41
4. We have τ (a) = 2.
5. We have σ(a) = 1 + 163 = 164. the sum of the positive divisors of a.
Exercise 4.
1. Find according to the values of n the remainder of the division of 2n by 3.
We have 20 ≡ 1 (mod 3), 21 ≡ 2 (mod 3), 22 ≡ 1 (mod 3). Therefore
42
3. 14x ≡ 28 (mod 60).
This congruence equation is equivalent to the equation 7 x = 14 in Z30 . Hence 13 7 x =
13 14, and hence x = 2. Therefore x ≡ 2 (mod 30).
Exercise 6. Use the Euclidean algorithm to find the inverse of a in Zn in the following cases:
−1
1. a = 2, n = 5: We have 5 = 2 × 2 + 1. Hence 2 × (−2) = 1 + 5, hence 2 = −2 = 3.
2. a = 5, n = 12: We have 12 = 2 × 5 + 2, 5 = 2 × 2 + 1. By back-substitution we get
−1
5 × 5 − 2 × 12 = 1, i.e. 5 × 5 = 1 + 2 × ×12. Hence 5 = 5.
3. a = 7, n = 30: We have 30 = 4 × 7 + 2, 7 = 3 × 2 + 1. By back-substitution we get
−1
13 × 7 − 3 × 30 = 1, i.e. 13 × 7 = 1 + 3 × ×30. Hence 7 = 13.
Supplementary exercises
Exercise 7. Solve the following congruences:
1. x + 7 ≡ 3 (mod 18), (sol. x ≡ 14 (mod 18))
2. 5x ≡ 12 (mod 100), (no solution since 12 does not divide 5)
3. 5x ≡ 15 (mod 100), (sol. x ≡ 3 (mod 20))
4. x2 + 3 ≡ 2 (mod 5), (sol. x ≡ 2 (mod 5) or x ≡ 3 (mod 5))
5. 4x ≡ 5 (mod 9), (sol. x ≡ 8 (mod 9))
6. 2x ≡ 7 (mod 17), (sol. x ≡ 12 (mod 17)).
43
Exercise 9. Find φ(n) in the following cases:
1. n = 10, (sol. φ(10) = 4)
2. n = 2455, (sol. φ(2455) = 1960)
3. n = 29, (sol. φ(29) = 28).
(b) We have
∞
[
x∈ Bn ⇐⇒ (∃n ≥ 1)(x ∈ Bn )
n=1
1
⇐⇒ (∃n ≥ 1)( ≤ x ≤ 2)
n
⇐⇒ x ∈ (0, 2],
44
(for the last step if x ∈ (0, 2], then choose n such that n > x,
1
and then we get
n ≤ x ≤ 2). Therefore
1
[∞
Bn = (0, 2].
n=1
T∞ T∞
(c) If x < 0 then / n=1 Cn . We have 0 ∈ n=1 Cn since 0 is in every Cn . If x > 0
T∞ x ∈
/ n=1 Cn because for n > x1 , i.e. n1 < x, we have x ∈
then x ∈ / Cn . Therefore
∞
\
Cn = {0}.
n=1
Exercise 13.
1. We have
[ [
x ∈ f −1 ( Aα ) ⇐⇒ f (x) ∈ Aα
α∈I α∈I
⇐⇒ (∃α ∈ I)(f (x) ∈ Aα )
⇐⇒ (∃α ∈ I)(x ∈ f −1 (Aα ))
[
⇐⇒ x ∈ f −1 (Aα ).
α∈I
Hence [ [
(∀x)(x ∈ f −1 ( Aα ) ⇐⇒ x ∈ f −1 (Aα )).
α∈I α∈I
Hence [ [
f −1 ( Aα ) = f −1 (Aα ).
α∈I α∈I
2. We have
\ \
x ∈ f −1 ( Aα ) ⇐⇒ f (x) ∈ Aα
α∈I α∈I
⇐⇒ (∀α ∈ I)(f (x) ∈ Aα )
⇐⇒ (∀α ∈ I)(x ∈ f −1 Aα )
\
⇐⇒ x ∈ f −1 (Aα ).
α∈I
Then \ \
(∀x)(x ∈ f −1 ( Aα ) ⇐⇒ x ∈ f −1 (Aα )).
α∈I α∈I
Then \ \
f −1 ( Aα ) = f −1 (Aα ).
α∈I α∈I
45
Exercise 14.
1. We have
[ \
x∈A∩( Bα ) ⇐⇒ x ∈ A and x ∈ ( Bα )
α∈I α∈I
⇐⇒ (x ∈ A) and (∃α ∈ I)(x ∈ Bα )
⇐⇒ (∃α ∈ I)(x ∈ A and x ∈ Bα )
⇐⇒ (∃α ∈ I)(x ∈ A ∩ Bα )
[
⇐⇒ x ∈ (A ∩ Bα ).
α∈I
Hence [ [
A∩( Bα ) = (A ∩ Bα ).
α∈I α∈I
2. We have
\ \
x∈A∪( Bα ) ⇐⇒ x ∈ A ou x ∈ ( Bα )
α∈I α∈I
⇐⇒ (x ∈ A) ou (∀α)(x ∈ Bα )
⇐⇒ (∀α ∈ I)(x ∈ A ou x ∈ Bα )
⇐⇒ (∀α ∈ I)(x ∈ A ∪ Bα )
\
⇐⇒ x ∈ (A ∪ Bα ).
α∈I
Hence \ \
A∪( Bα ) = (A ∪ Bα ).
α∈I α∈I
Exercise 15.
1. We have
x ∈ f −1 (Ac ) ⇐⇒ f (x) ∈ Ac
⇐⇒ f (x) ∈
/A
/ f −1 (A)
⇐⇒ x ∈
⇐⇒ x ∈ [f −1 (A)]c
Then
(∀x)(x ∈ f −1 (Ac ) ⇐⇒ x ∈ [f −1 (A)]c ).
Then
f −1 (Ac ) = [f −1 (A)]c .
2. We have
x ∈ f −1 (A) =⇒ f (x) ∈ A
=⇒ f (x) ∈ B (car A ⊆ B)
=⇒ x ∈ f −1
(B).
46
Then
f −1 (A) ⊆ f −1 (B).
A ⊆ f −1 [f (A)].
4. We have
\ \
x∈( Bα )c ⇐⇒ x ∈
/ Bα
α∈I α∈I
⇐⇒ (∃α ∈ I)(x ∈
/ Bα )
⇐⇒ (∃α ∈ I)(x ∈ Bαc )
[
⇐⇒ x ∈ Bαc .
α∈I
Hence \ [
( Bα )c = Bαc .
α∈I α∈I
Exercise 16.
1. We have
\ \
(x, y) ∈ ( Aα ) × B ⇐⇒ x ∈ Aα and y ∈ B
α∈I α∈I
⇐⇒ (∀α ∈ I)(x ∈ Aα ) and (y ∈ B)
⇐⇒ (∀α ∈ I)(x ∈ Aα and y ∈ B)
⇐⇒ (∀α ∈ I)((x, y) ∈ Aα × B)
\
⇐⇒ (x, y) ∈ (Aα × B).
α∈I
Hence \ \
( Aα ) × B = (Aα × B).
α∈I α∈I
2. We have
[ [
(x, y) ∈ ( Aα ) × B ⇐⇒ x ∈ Aα and y ∈ B
α∈I α∈I
⇐⇒ (∃α ∈ I)(x ∈ Aα ) and (y ∈ B)
⇐⇒ (∃α ∈ I)(x ∈ Aα and y ∈ B)
⇐⇒ (∃α ∈ I)((x, y) ∈ Aα × B)
[
⇐⇒ (x, y) ∈ (Aα × B).
α∈I
Hence [ [
( Aα ) × B = (Aα × B).
α∈I α∈I
47
Exercise 17.
1. Suppose that x ∈ Aα . Hence we have x ∈
/ Ax+1 = [x + 1, +∞[. Hence
T
α∈R
\
Aα = ∅.
α∈R
2. We have
[
x∈ Aα ⇐⇒ (∃α ∈ R)(x ∈ Aα )
α∈R
⇐⇒ (∃α ∈ R)(x ∈ [α, +∞[)
⇐⇒ x ∈ R.
Hence [
Aα = R.
α∈R
48
Solutions No. 2
Exercise 1. Consider the Caesar cipher given by P = C = K = Z26 , with Z26 representing the
26 letters of the alphabet (A = 1, B = 2, . . . , Y = 25, Z = 0).
1. Given that k = 13, encrypt the plaintext message FIRST.
The encryption function ek : Z26 → Z26 is given by
ek (m) = m + k.
We have
ek (F ) = ek (6) = 6 + 13 = 19 = S
ek (I) = ek (9) = 9 + 13 = 22 = V
ek (R) = ek (18) = 18 + 13 = 5 = E
ek (S) = ek (19) = 19 + 13 = 6 = F
ek (T ) = ek (20) = 20 + 13 = 7 = G.
dk (c) = c − k.
We have
dk (E) = dk (5) = 5 − 13 = 18 = R
dk (R) = dk (18) = 18 − 13 = 5 = E
dk (Q) = dk (17) = 17 − 13 = 4 = D.
Exercise 2. Consider the affine cipher given by P = C = Z26 , K = Z∗26 × Z26 , with Z26
representing the 26 letters of the alphabet (A = 1, B = 2, . . . , Y = 25, Z = 0).
ek (m) = 7m + 3.
We have
ek (D) = ek (4) = 7 × 4 + 3 = 5 = E
ek (A) = ek (1) = 7 × 1 + 3 = 5 = G
ek (Y ) = ek (4) = 7 × 25 + 3 = 22 = V
49
2. Decrypt the ciphertext RLF.
The decryption function dk : Z26 → Z26 is given by
Using the Euclidean algorithm, we find that the inverse of 7 in Z26 is 15.
We have
dk (R) = dk (18) = 15(18 − 3) = 17 = Q
dk (L) = dk (12) = 15(12 − 3) = 5 = E
dk (F ) = dk (6) = 15(6 − 3) = 19 = S
k1 = (m − m′ )−1 (c − c′ )
= 11−1 × (−17)
= (−7) × (−17)
= 15.
2 7
k= .
13 9
1. The inverse of k:
We have
9
−7
k −1
= (2 × 9 − 13 × 7) −1
.
−13 2
7 9
= .
13 16
2. Using the Hill cipher with key k, encrypt the plaintext message HELP.
50
and
We have
541 = 15 × 34 + 31 → 31 = 541 − 15 × 34
34 = 1 × 31 + 3 → 3 = 34 − 1 × 31
31 = 10 × 3 + 1 → 1 = 31 − 10 × 3.
By back-substitution we get
51
3. Suppose that Alice and Bob decide to use Z601 (601 is prime) for the affine cipher, and 601
is public knowledge. Suppose that Eve intercepts the ciphertexts c1 = 324 and c2 = 381,
and manages to find out the corresponding plaintexts m1 = 387 and m2 = 491. Determine
the private key.
(the inverse of 4 is −150 = 451 since −150 × 4 = 1 − 601). Therefore k1 = 41, and hence
k2 = c1 − k1 m1 = 83. Therefore
k = (41, 83).
52
Solutions No. 3
Exercise 1.
1. We have (p, g, a) = (127, 2, 17), h = 53. Let k = 5
We have
s1 = g k mod p
= 23 mod 127
= 8.
and
s2 = (h − as1 )k −1 mod(p − 1)
= (53 − 17 · 8)5−1 mod(126)
= (53 − 17 · 8)(−25) mod(126)
= 59.
Therefore the signature (s1 , s2 ) is given by
(s1 , s2 ) = (8, 59).
Therefore we have
As1 ss12 mod p = 88 · 859 mod 127
= 867 mod 127
= 16.
and
g h mod p = 253 mod 127
= 16.
Exercise 2.
1. We have the public key (n, e) = (391, 13). The message m = 54 ∈ Z391 is encrypted as
c = me mod 391
= 5413 mod 391
= (544 )3 · 54 mod 391
= (370)3 · 54 mod 391
= 386.
53
2. We have 391 = 17 × 23
3. We have φ(391) = 16 × 22 = 352. The inverse of e = 13 in Z352 is d = 325 = 52 × 13 and
hence the private key is (n, d) = (391, 325). The ciphertext c = 21 is deciphered as
m = cd mod 391
= 21325 mod 391
= (215 )65 mod 391
= (1065 )13 mod 391
= ((38)5 )2 · (38)3 mod 391
= (191)2 · (38)3 mod 391
= 327.
s = md mod 391
= 26325 mod 391
= (265 )65 mod 391
= (595 )13 mod 391
= ((349)4 )3 · 349 mod 391
= (118)3 · 349 mod 391
= 246.
Exercise 3.
B = g b mod p
= 2871 mod 1373
= (213 )67 mod 1373
= (1327)67 mod 1373
= ((−46)4 )16 · (1327)3 mod 1373
= (1034 )4 · 147 mod 1373
= (579)4 · 147 mod 1373
= 267 · 147 mod 1373
= 805
54
2. We have
9742 ≡ −67[1373]
(974)4 ≡ 370[1373]
9748 ≡ 973[1373]
97416 ≡ 732[1373]
97432 ≡ 354[1373]
97464 ≡ 373[1373]
974128 ≡ 456[1373]
974256 ≡ 613[1373]
974512 ≡ 940[1373].
s = Ab mod p
= 974871 mod 1373
= 9741+2+4+32+64+256+512 mod 1373
= 9741 · 9742 · 9744 · 97432 · 97464 · 974256 · 974512 mod 1373
= ((−399) · (−67) · 370 · 354) · (373 · 613 · 940) mod 1373
= 582 · 640 mod 1373
= 397
55
A.2 Tests and exams
University of Bejaia 21 December 2022
Department of OR Duration: 1 hour
Level : SDAD1
Module : Cryptography
Academic year: 22/23
Test
56
Solutions
2. We have
23 + 32 = 55
= 42 + 13
= 13
and
23 · 5 = 115
= 2 × 42 + 31
= 31.
3. The congruence 34x ≡ 30 (mod 84) is equivalent to the equation 17 x = 15 in Z42 . We have
34x ≡ 30 (mod 84) ⇐⇒ 17 x = 15
⇐⇒ 5 17 x = 5 15
⇐⇒ x = 5 15
⇐⇒ x = 33
⇐⇒ x ≡ 33 (mod 42).
57
4. Solving 17x + 42y = 2:
From the first question we have 5 × 17 − 2 × 42 = 1, and hence 10 × 17 − 4 × 42 = 2.
Substracting this equation from 17x + 42y = 2 we get
Since 42 divides 17(x−5) and gcd(17, 42) = 1, then 42 divides x−10. Therefore x−10 = 42t
for some integer t, i.e. x = 42t + 10. Substituting x in 17(x − 5) = −42(y + 2) we get
y = −17t − 4.
58
University of Bejaia
Department of OR
Level: SDAD1
Module: Cryptography
Academic year: 22/23
Exercise 2 (7 marks).
Exercise 3 (6 marks).
Consider the matrix k with entries in Z17 :
2 7
k= .
5 15
2. Using the Hill cipher with key k, encrypt the plaintext m = (3, 5)⊤ .
3. Find the plaintext given that the ciphertext is c = (7, 3)⊤ .
59
University of Bejaia 8 January 2023
Department of OR Duration: 1 h 30 min
Level: SDAD1
Module: Cryptography
Academic year: 22/23
Examination paper
Exercise 1 (7 marks).
Exercise 2 (7 marks).
Let a = 132 and b = 825.
1. Find the prime factorization of the numbers a and b.
2. Find gcd(a, b) and ℓcm(a, b).
Exercise 3 (6 marks).
Consider the matrix k with entries in Z23 :
2 6
k= .
5 17
60
Solutions
1. We have
37 = 2 × 13 + 11 → 11 = 37 − 2 × 13
13 = 1 × 11 + 2 → 2 = 13 − 1 × 11
11 = 2 × 5 + 1 → 1 = 11 − 2 × 5.
2. We have
25 + 17 = 42 = 5, 12 · 23 = 176 = 17.
3. We have
61
3. We have
div+ (a) = {1, 3, 11, 33, 2, 6, 22, 66, 4, 12, 44, 132}.
4. We have
φ(a) = φ(22 ) × φ(3) × φ(11) = 2 × 2 × 10 = 40.
2 6
k= .
5 17
1. We have
17
−6
k −1
= (2 · 17 − 5 · 6) −1
−5 2
−1 17
−6
= (4)
−5 2
17 −6
=6
−5 2
10 10
= .
16 12
62
University of Bejaia 24 june 2023
Department of OR Duration: 1 h 30 min
Level: SDAD1
Module: Cryptography
Academic year: 22/23
Exercise 1 (7 marks).
Let a = 600 and b = 315.
4. Find φ(a).
Exercise 2 (7 marks).
Exercise 3 (6 marks).
Consider the affine Hill cipher with Z17 and key k = (k1 , k2 ) given by
5 3
k1 = and k2 = (3, 4)⊤ .
7 6
63
Solutions
3. We have
τ (b) = 3 × 2 × 2 = 12.
4. We have
φ(a) = φ(23 × 3 × 52 )
= φ(23 ) × φ(3) × φ(52 )
= 4 × 2 × 20
= 160.
1. We have
29 = 1 × 16 + 13 → 13 = 29 − 1 × 116
16 = 1 × 13 + 3 → 3 = 16 − 1 × 13
13 = 4 × 3 + 1 → 1 = 13 − 4 × 3.
2. We have
22 + 19 = 41 = 12, 1 · 13 = 143 = 27.
3. We have
64
4. Determine all (x, y) ∈ Z2 such that 15x + 21y = 3.
We have
Since 13 divides 7(x − 6) and gcd(13, 7) = 1 then 13 divides x − 6, and therefore x − 6 = 13t
for some integer t. Hence y + 3 = −7t.
If S = {(x, y) ∈ Z2 : 7x + 13y = 3} then
1. For
5 3
k1 = .
7 6
we have
6
−3
k1−1 = (5 · 6 − 7 · 3)−1
−7 5
6 −3
= (9)−1
−7 5
6 −3
=2
−7 5
12 11
= .
3 10
65
A.3 List of notations
div(a) the set of divisors of a
div+ (a) the set of positive divisors of a
div(a, b) the set of common divisors of a and b
muℓ(a) the set of multiples of a
muℓ(a, b) the set of common multiples of a and b
66
A.4 Glossary
Set : ensemble
Subset : sous-ensemble
Sum : somme
Integers : entiers relatifs
Real number : nombre réel
Remainder : reste
Invertible : inversible
Prime number : nombre premier
Natural number : nombre naturel
Non-negative : positif
Positive : strictement positif
Set of divisors of a : ensemble des diviseurs de a
Set of positive divisors of a : ensemble des diviseurs positifs de a
Set of common divisors of a and b : ensemble des diviseurs communs de a et de b
Set of multiples of a : ensemble des multiples de a
Set of common multiples of a and b : ensemble des multiples communs de a et de b
Greatest common divisor of a and b : plus grand commun diviseur de a et de b
Least common multiple of a and b : plus petit commun multiple de a et de b
Number of positive divisors of a : nombre des diviseurs positifs de a
Sum of the positive divisors of a : somme des diviseurs positifs de a
Euler totient function : la fonction indicatrice d’Euler
Encrypt, encipher : crypter, chiffrer
Decrypt, decipher : décrypter, déchiffrer,
Encryption, encipherment : crypter, chiffrement
Decryption, decipherment : décryptage, déchiffrement
Encyption function : fonction de chiffrement
Decryption function : fonction de déchiffrement
Key : clé
Key space : espace des clés
Plaintext : message en clair
Plaintext space : espace des messages en clair
Ciphertext : message chiffré
Ciphertext space : espace des messages chiffrés
Cryptosystem : cryptosystème
Cryptanalysis : cryptanalyse
Cryptography : cryptographie
Cryptology : cryptologie
Caesar cipher (shift cipher) : chiffre de César
Vigenère cipher : chiffre de Vigenère
Affine cipher : chiffre affine
Hill cipher : chiffre de Hill
Affine Hill cipher : chiffre de Hill affine
Hash function : fonction de hachage
Digital signature : signature numérique
67
Bibliography
[2] E. Biham, A. Shamir, Differential cryptanalysis of the Data Encryption Standard, Springer-
Verlag, New York, 1993.
[3] E. Biham, A. Shamir, Differential cryptanalysis of full-16-round DES, Springer, 1998.
[4] M. Barakat, C. Eder, T. Hanke, An introduction to cryptography, Lecture notes, 2018.
[12] National Institute of Standards and Technology, DES modes of operation, FIPS Publication
81, NIST, 1980.
[13] National Institute of Standards and Technology, Data Encryption Standard (DES), FIPS
publication 46, NIST, 1977.
[14] National Institute of Standards and Technology, Advanced Encryption Standard (AES),
FIPS publication 197, NIST, 2001.
[15] NIST–DSS, Digital Signature Standard (DSS). FIPS Publication 186-2, National Institue
of Standards and Technology, 2004.
[16] W. Diffie, The first ten years of public key cryptology, G.J. Simmons (ed.), in Contemporary
Cryptology (IEEE, New York), pp. 135–175, 1992.
68
[17] W. Diffie, M. E. Hellman, New directions in cryptography, IEEE Trans. Inf. Theory IT-
22(6), pp. 644–654, 1976.
[18] T. ElGamal, A public key cryptosystem and a signature scheme based on discrete loga-
rithms, IEEE Trans. Inf. Theory 31(4), pp. 469–472, 1985.
110] R. L. Rivest, A. Shamir, L. Adleman, A method for obtaining digital signatures and
public-key cryptosystems, Commun. ACM 21(2), pp. 120–126, 1978.
[19] S. J. Nielson C. K. Monson, Practical cryptography with Python: Learning correct cryptog-
raphy by example, Springer, 2019.
[20] Jean-Louis Pons, Introduction à la cryptographie, cours ENSAM Aix en Provence, 2003.
69