You are on page 1of 31

University of Kufa

Faculty of Education
Department of Computer Science

Mathematics Lectures for Master’s Computer Science


Second Semester (2023- 2024)

Chapter Two: Number Theory


1) Divisibility:
Definition 1.1: Let 𝑎 and 𝑏 be non zero integer numbers. We call 𝑎 divides 𝑏 (notation 𝑎 𝑏 , if
there is an integer 𝑘 such that 𝑎𝑘 = 𝑏.
The following phrases all say the same thing: 𝑎 | 𝑏,
𝑎 divides 𝑏,
𝑎 is a divisor of 𝑏,
𝑎 is a factor of 𝑏,
𝑏 is divisible by 𝑎,
𝑏 is a multiple of 𝑎.
From Definition 1.1: For all 𝑛 ∈ ℤ (𝑛 is an integer number), 𝑛|0; 𝑛|𝑛; and ±1|𝑛.
Also, 0|𝑛 implies 𝑛 = 0.

2
1) Divisibility:
Definition 1.2: Let 𝑏 and 𝑐 be non zero integer numbers. A number of the form
𝑠𝑏 + 𝑡𝑐 is called an integer linear combination of 𝑏 and 𝑐, for all 𝑠, 𝑡 ∈ ℤ.

The following lemma collects some basic facts about divisibility.

Lemma 1.3: Let 𝑎, 𝑏 and 𝑐 be non zero integer numbers.

1) If 𝑎 | 𝑏 and 𝑏 | 𝑐, then 𝑎 | 𝑐.

2) If 𝑎 | 𝑏 and 𝑎 | 𝑐, then 𝑎 | 𝑠𝑏 + 𝑡𝑐 for all 𝑠, 𝑡 ∈ ℤ.

3) For all 𝑐 ≠ 0, 𝑎 | 𝑏 if and only if 𝑐𝑎 |𝑐𝑏. That is, if 𝑎 divides 𝑏 and 𝑐, then 𝑎
divides every linear combination of 𝑏 and 𝑐.
3
1) Divisibility:
Definition 1.4: A non zero integer number 𝑛 is called a linear combination of the
integer numbers 𝑏0 , 𝑏1 , … , 𝑏𝑘 where 𝑘 ∈ ℤ+ ∪ {0}, if
𝑛 = 𝑠0 𝑏0 + 𝑠1 𝑏1 + ⋯ +𝑠𝑘 𝑏𝑘
for some integer numbers 𝑠0 , 𝑠1 , … , 𝑠𝑘 .

Theorem 1.5: (Division Theorem) Let 𝑛 and 𝑑 be non zero integer numbers such
that 𝑑 ≠ 0. Then, there exists a unique pair of integers 𝑞 and 𝑟, such that
𝑛 = 𝑞. 𝑑 + 𝑟 and 0 ≤ 𝑟 < |𝑑|.
The number 𝑞 is called the quotient and the number 𝑟 is called the remainder of 𝑛
divided by 𝑑. We use the notation qcn(𝑛, 𝑑) for the quotient and rem(𝑛, 𝑑) for the
remainder.
For example, rem −11,7 = 3 and qcnt −11,7 = −2, since −11 = −2 . 7 + 3.
4
2) The Greatest Common Divisor:
Definition 2.1: Let 𝑎 and 𝑏 be non zero integer numbers. A non zero integer
number that divides 𝑎 and 𝑏 is called a common divisor of 𝑎 and 𝑏. The greatest
common divisor of 𝑎 and 𝑏 is written gcd 𝑎, 𝑏 .

For example, gcd 18,24 =6.

Remarks 2.2: Some immediate consequences of the definition of gcd are that

gcd 𝑛, 1 = 1.

gcd 𝑛, 𝑛 = gcd 𝑛, 0 = |𝑛| for 𝑛 ≠ 0.

where the last equality follows from the fact that everything is a divisor of 0.
5
2) The Greatest Common Divisor:
Theorem 2.3: Let 𝑎 and 𝑏 be non zero integer numbers. For greatest common
divisor, there are many properties:
1) gcd(𝑎, 𝑏) ≥ 1.
2) gcd(𝑎, 𝑏) = gcd(𝑏, 𝑎).
3) gcd(𝑎, 𝑏) = gcd(|𝑎|, |𝑏|),
since gcd(𝑎, 𝑏) = gcd(−𝑎, 𝑏) = gcd(𝑎, −𝑏) = gcd(−𝑎, −𝑏).
Lemma 2.4: For 𝑏 ≠ 0, gcd 𝑎, 𝑏 = gcd 𝑏, rem(𝑎, 𝑏) .
That is, if 𝑎 = 𝑞𝑏 + 𝑟, then gcd(𝑎, 𝑏) = gcd(𝑏, 𝑟).
For example, gcd 15, 4 = gcd(4, 11) = gcd(4, 7) = gcd(4, 3) =1.

6
2) The Greatest Common Divisor:
Example 2.5: Find the gcd of 1147 and 899.
Solution:
gcd(1147, 899) = gcd(899, rem(1147,899)=248)
1147 = 1 . 899 + 248
= gcd(248, rem(899, 248)=155) 899 = 3 . 284 + 155
= gcd(155, rem(248,155)=93) 284 = 1. 155 + 93
= gcd(93, rem(115,93)=62) 155 = 1. 93 + 62
= gcd(62, rem(93,62)=31) 93 = 1. 62 + 31
= gcd(31, rem(62,31)=0) 62 = 2. 31 + 0
= 31. ∴gcd(1147, 899) =31.
Then, gcd(1147, 899) =31.

7
2) The Greatest Common Divisor:
The Euclidean algorithm can be described as follows:
Theorem 2.6: (The Euclidean algorithm) Let 𝑎 and 𝑏 be non zero integer numbers such that
𝑎 ≥ 𝑏 > 0, whose greatest common divisor is desired.
If 𝑏 | 𝑎, then gcd 𝑎, 𝑏 = 𝑏.
If 𝑏 ∤ 𝑎, then gcd 𝑎, 𝑏 = 𝑏. Then, we make a repeated application of the division algorithm
to obtain a series of division equations, which eventually terminate with a zero remainder:
𝑎 = 𝑏𝑞1 + 𝑟1 , 0 < 𝑞1 < 𝑏,
𝑏 = 𝑟1 𝑞2 + 𝑟2 , 0 < 𝑟2 < 𝑟1 ,
𝑟1 = 𝑟2 𝑞3 + 𝑟3 , 0 < 𝑟3 < 𝑟2 ,
···
𝑟𝑗−2 = 𝑟𝑗−1 𝑞𝑗 + 𝑟𝑗 , 0 < 𝑟𝑗 < 𝑟𝑗−1 ,
𝑟𝑗−1 = 𝑟𝑗 𝑞𝑗+1 .
The greatest common divisor gcd 𝑎, 𝑏 of 𝑎 and 𝑏 is rj , the last nonzero remainder in the
division process.
8
2) The Greatest Common Divisor:
Example 2.7: By using Euclid’s algorithm, find the gcd(19, 7).
Solution: 19 = 7 · 2 + 5
7=5·1+2
5=2·2+1
2=1·2+0
Therefore, gcd(19, 7)= 1.
Example 2.8: Find the gcd of 42823 and 6409.
Solution: 42823 = 6 . 6409 + 4369
6409 = 1 . 4369 + 2040
4369 = 2. 2040 + 289
2040 = 7. 289 + 17
289 = 17. 17 + 0
Therefore, gcd(42823, 6409) = 17.
9
2) The Greatest Common Divisor:
Example 2.9: By using Euclid’s algorithm, compute gcd(1914, 899).
Solution: 1914 = 2 · 899 + 116
899 = 7 · 116 + 87
116 = 1 · 87 + 29
87 = 3 · 29 + 0
Therefore, gcd(1914, 899) = 29.
The following theorem is called the extended Euclidean algorithm ( or The Pulverizer)
allows to find not only the gcd, but also the values of the coefficients 𝑠 and 𝑡.
Theorem 2.10: Let 𝑎 and 𝑏 be non zero integer numbers. The greatest common divisor of 𝑎
and 𝑏 is a linear combination of 𝑎 and 𝑏. That is, gcd 𝑎, 𝑏 = 𝑠𝑎 + 𝑡𝑏, for some integers 𝑠
and 𝑡.

10
2) The Greatest Common Divisor:
Every linear combination of 𝑎 and 𝑏 is divisible by any common factor of a and b, so it
is certainly divisible by the greatest of these common divisors. Since any constant multiple of
a linear combination is also a linear combination, Theorem 2.10 implies that any multiple of
the gcd is a linear combination, giving:
Corollary 2.11: Let 𝑎 and 𝑏 be non zero integer. An integer is a linear combination of 𝑎 and
𝑏, if and only if it is a multiple of gcd 𝑎, 𝑏 .
Example 2.12: Following Euclid’s algorithm, we can compute the gcd of 259 and 70 as
follows:
gcd(259, 70) = gcd(70, 49) since rem(259, 70)=49
= gcd(49, 21) since rem(70, 49)=21
= gcd(21, 7) since rem(49, 21)=7
= gcd(7, 0) since rem(21, 7)=0
= 7.
Then, gcd(259, 70) =7.
11
2) The Greatest Common Divisor:
The Pulverizer goes through the same steps, but requires some extra bookkeeping along the way, as follows:

𝑥 𝑦 (rem(𝑥, 𝑦)) = 𝑥 - 𝑞. 𝑦
259 70 49 = 𝑎 - 3. 𝑏
= 𝑏 - 1.49
= 𝑏 - 1. (𝑎 − 3. 𝑏)
= −1. 𝑎 + 4. 𝑏
49 21 7 = 49 - 2.21
=(𝑎 − 3. 𝑏)- 2. (−1. 𝑎 + 4. 𝑏)
= 3. 𝑎-11. 𝑏
21 7 0

We began by initializing two variables, 𝑥 = 𝑎 and 𝑦 = 𝑏. In the first two columns above, we carried out Euclid’s
algorithm. At each step, we computed rem(𝑥, 𝑦) which equals 𝑥 - qcnt (𝑥, 𝑦) . 𝑦. Then, in this linear combination of
𝑥 and 𝑦, we replaced 𝑥 and 𝑦 by equivalent linear combinations of a and b, which we already had computed. After
simplifying, we were left with a linear combination of 𝑎 𝑎𝑛𝑑 𝑏 equal to rem(𝑥, 𝑦) , as desired.
12
2) The Greatest Common Divisor:
Example 2.13: By Pulverizer find gcd(50, 21).
𝑥 𝑦 (rem(𝑥, 𝑦)) = 𝑥 - 𝑞. 𝑦
50 21 8 = 50 - 2.21
21 8 5 = 21 - 2.8
= 21 - 2. (50 − 2.21)
= −1. 50 + 5.21
8 5 3 = 8 - 1.5
=(50 − 2.21)- 1. (−2. 50 + 5.21)
= 3. 50-7. 21
5 3 2 = 5-1.3
= ( -2.50 + 5.21 ) - 1. ( 3.50 - 7.21 )
=-5.50 + 12.21
3 2 1 =3-1.2
= (3.50 - 7.21 ) - 1. ( -5.50 + 12.21)
= 8.50 – 19.21
2 1 0
13
2) The Greatest Common Divisor:
The following theorem shows properties of the greatest common divisor.

Theorem 2.14: Let 𝑎, 𝑏, 𝑐 and 𝑑 be non zero integer numbers. Then:

1) gcd(𝑘𝑎, 𝑘𝑏) = 𝑘 . gcd 𝑎, 𝑏 , for all 𝑘 > 0.

2) (𝑑|𝑎 and 𝑑|𝑏), if and only if 𝑑| gcd 𝑎, 𝑏 .

3) If gcd 𝑎, 𝑏 =1 and gcd 𝑎, 𝑐 =1, then gcd 𝑎, 𝑏𝑐 =1.

4) If 𝑎|𝑏𝑐 and gcd 𝑎, 𝑏 =1, then 𝑎|𝑐.

14
3) Prime Mysteries:
Definition 3.1: A prime is a number greater than 1 that is divisible only by itself
and 1. A number other than 0, 1, and -1 that is not a prime is called composite.
Here are three famous mysteries:
Definition 3.2: If 𝑝 and 𝑝 + 2 are primes, then the are called twin prime.
For example, 2 and 3, 3 and 5, 5 and 7, 11 and 13, 17 and 19, 27 and 29, …etc.
Conjecture 3.3: (Twin Prime Conjecture) There are infinitely many primes 𝑝
and 𝑝 + 2 is also a prime.
Conjecture 3.4: (Goldbach’s Conjecture) Every even integer greater than 2 is
the sum of two primes.
For example, 4 = 2 + 2, 6 = 3 + 3, 8 = 3 + 5, …etc.

15
3) Prime Mysteries:
Definition 3.5: Let 𝑛 be a positive integer number such that 𝑛 ≥ 1, then 𝜋(𝑛) is
the number of primes up to the integer number 𝑛 and it is defined as:
𝜋 𝑛 = | 𝑝 ∈ {2,3, … , 𝑛}: 𝑝 𝑖𝑠 𝑝𝑟𝑖𝑚𝑒 |.
For example, 𝜋 1 =0, 𝜋 2 = 1, and 𝜋 10 = 4 , because 2, 3, 5, and 7 are the
primes less than or equal to 10.
Theorem 3.6: (Prime Number Theorem) Let 𝑛 be an integer number, then:
𝜋(𝑛)
lim = 1.
𝑛→∞ 𝑛/ ln 𝑛
Theorem 3.7: (Chebyshev’s Theorem on Prime Density) Let 𝑛 be an integer
𝑛
number such that 𝑛 > 1, then: 𝜋 𝑛 > .
3 ln 𝑛

16
4) The Fundamental Theorem of Arithmetic:
Theorem 4.1: (Fundamental Theorem of Arithmetic) Every positive integer is
a product of a unique weakly decreasing sequence of primes.
For example, For example, 12 is the product of the weakly decreasing sequence
of primes: 12 3 . 2. 2.
And, 75237393= is the product of the weakly decreasing sequence of primes:
75237393 = 23. 17. 17. 11. 7. 7. 7. 3.
Lemma 4.2: If 𝑝 is a prime and 𝑝 | 𝑎𝑏, then 𝑝 | 𝑎 or 𝑝 | 𝑏.
Lemma 4.3: Let 𝑝 be a prime. If 𝑝 | 𝑎1 𝑎2 …𝑎𝑛 , then 𝑝 divides some 𝑎𝑖 ,
for 𝑖 ∈ ℤ+ and 𝑛 ≥ 2.
17
5) Turing’s Code (Version 1.0):
Definition 5.1: (Turing’s Code (Version 1.0)) To translate a text message into
an integer, we perform mathematical operations on it. Here is one approach:
replace each letter of the message with two digits (A = 01, B = 02, C = 03, etc.)
and string all the digits together to form one huge number. Turing’s code requires
the message to be a prime number. For description, let 𝑚 be the unencoded
message, 𝑚ෝ be the encrypted message and 𝑘 is the key.
Beforehand: The sender and receiver agree on a secret key, which is a large
prime 𝑘.
Encryption: The sender encrypts the message m by computing: 𝑚=
ෝ 𝑚. 𝑘.

𝑚
Decryption: The receiver decrypts bm by computing: = 𝑚.
𝑘

18
5) Alan Turing:
For example, the message “victory” could be translated this way:
v i c t o r y
→ 22 09 03 20 15 18 25
Suppose that the secret key is the prime number 𝑘 = 22801763489 and the
message 𝑚 is “victory.” Then the encrypted message is:
𝑚=
ෝ 𝑚. 𝑘 = 2209032015182513 . 22801763489= 50369825549820718594667857
-The general problem of determining whether a large number is prime or
composite has been studied for centuries.
-If the sender transmits a second message using Turing’s code and the same key 𝑘,
we get: 𝑚 ෞ1 =𝑚1 𝑘 and 𝑚 ෞ2 =𝑚2 . 𝑘 , since gcd(𝑚
ෞ1 , 𝑚
ෞ2 )= 𝑘. So after the second
message is sent, the Nazis can recover the secret key and read every message.
19
6) Modular Arithmetic:
Definition 6.1: Let 𝑎 and 𝑏 be non zero integer numbers and let 𝑛 be a positive integer
number. Then, 𝑎 is called congruent to 𝑏 modulo 𝑛 if and only if 𝑛 | (𝑎 – 𝑏). This is written
as: 𝑎 ≡ 𝑏 (𝑚𝑜𝑑 𝑛).
For example: 29 ≡ 15 (𝑚𝑜𝑑 7), because 7 | (29 – 15).
Lemma 6.2: (Remainder) Let 𝑎 and 𝑏 be non zero integer numbers and let 𝑛 be a positive
integer number. Then, 𝑎 ≡ 𝑏 𝑚𝑜𝑑 𝑛 , if and only if 𝑟𝑒𝑚(𝑎, 𝑛) = 𝑟𝑒𝑚(𝑏, 𝑛).
For example: 1) 29 ≡ 𝑟𝑒𝑚 29, 7 𝑚𝑜𝑑 7 = 1.
2) 29 ≡ 15 (𝑚𝑜𝑑 7), because 𝑟𝑒𝑚 29, 7 = 1 = 𝑟𝑒𝑚(15,7).
Lemma 6.3: (Facts About Congruence) Let 𝑎, 𝑏 and 𝑐 be non zero integer numbers and let 𝑛
be a positive integer number such that 𝑛 ≥ 1. Then:
1) 𝑎 ≡ 𝑎 (𝑚𝑜𝑑 𝑛). (reflexivity)
2) 𝑎 ≡ 𝑏, if and only if 𝑏 ≡ 𝑎 (𝑚𝑜𝑑 𝑛). (symmetry)
3) 𝑎 ≡ 𝑏 and 𝑏 ≡ 𝑐 implies 𝑎 ≡ 𝑐 (𝑚𝑜𝑑 𝑛). (transitivity)
20
6) Modular Arithmetic:
Corollary 6.4: Let 𝑎 be non zero integer numbers and let 𝑛 be a positive integer number. Then:
𝑎 ≡ 𝑟𝑒𝑚 (𝑎, 𝑛) (𝑚𝑜𝑑 𝑛).
Still another way to think about congruence modulo n is that it defines a partition of the integers
into n sets so that congruent numbers are all in the same set. For example, suppose that we’re
working modulo 3. Then we can partition the integers into 3 sets as follows:
{ … , −6, −3, 0, 3, 6, 9, …}
{ … , −5, −2, 1, 4, 7, 10, …}
{ … , −4, −1, 2, 5, 8, 11,…}
according to whether their remainders on division by 3 are 0, 1, or 2.
Lemma 6.5: (Congruence) Let 𝑎, 𝑏, 𝑐 and 𝑑 be non zero integer numbers and let 𝑛 be a
positive integer number. If 𝑎 ≡ 𝑏 (𝑚𝑜𝑑 𝑛) and 𝑐 ≡ 𝑑 (𝑚𝑜𝑑 𝑛), then:
1) 𝑎 + 𝑐 ≡ 𝑏 + 𝑑 (𝑚𝑜𝑑 𝑛).
2) 𝑎𝑐 ≡ 𝑏𝑑 (𝑚𝑜𝑑 𝑛).

21
7) Remainder Arithmetic :
Definition 7.1: (General Principle of Remainder Arithmetic) To find the remainder on
division by 𝑛 of the result of a series of additions and multiplications, applied to some integers:

1) Replace each integer operand by its remainder on division by 𝑛.

2) Keep each result of an addition or multiplication in the range {0,1,2,…, 𝑛 − 1} by


immediately replacing any result outside that range by its remainder on division by 𝑛.

For example, suppose we want to find rem((444273456789 , 1555558585555 ) 4036666666 ,36).

Since rem(44427, 36) = 3, rem(15555858, 36)= 6, and rem(403, 36)= 7.

We have rem(3,36) = 3, rem(32 ,36) = 9, rem(33 ,36) = 27, and rem(34 ,36) = 9.

Therefore, rem(33456789 ,36) = rem(33 ,36) = 27.


22
7) Remainder Arithmetic:
Definition 7.2: Let 𝑛 be a positive integer number such that 𝑛 ≥ 1. The notations +𝑛 and . 𝑛 are
defined as follows: 𝑖 +𝑛 𝑗 = rem 𝑖 + 𝑗, 𝑛 , and 𝑖 . 𝑛 𝑗 = rem 𝑖. 𝑗, 𝑛 . The set of integers in
the range {0,1,2,…,𝑛 − 1} together with the operations +𝑛 and . 𝑛 is referred to as ℤ𝑛 , the ring of
integers modulo 𝑛. since ℤ𝑛 satisfies all of the following equalities:
1) 𝑖 +𝑛 𝑗 ∈ ℤ𝑛 (closedness of +𝑛 on ℤ𝑛 ).
2) 𝑖 +𝑛 𝑗 +𝑛 𝑘 = 𝑖 +𝑛 (𝑗 +𝑛 𝑘) (associativity of +𝑛 ).
3)𝑘 +𝑛 0 = 𝑘 = 0 +𝑛 𝑘 (identity for +𝑛 ).
4) 𝑘 +𝑛 −𝑘 = 0 = −𝑘 +𝑛 𝑘 (inverse for +𝑛 ).
5) 𝑖 +𝑛 𝑗 = 𝑗 +𝑛 𝑖 (commutativity of +𝑛 ). 6) 𝑖 .𝑛 𝑗 ∈ ℤ𝑛 (closedness of . 𝑛 on ℤ𝑛 ).
7) 𝑖. 𝑛 𝑗 . 𝑛 𝑘 = 𝑖. 𝑛 (𝑗. 𝑛 𝑘) (associativity of . 𝑛 ).
8)𝑘. 𝑛 1 = 𝑘 = 1. 𝑛 𝑘 (identity for . 𝑛 ).
9) 𝑖. 𝑛 𝑗 = 𝑗. 𝑛 𝑖 (commutativity of . 𝑛 ).
10) 𝑖. 𝑛 𝑗 +𝑛 𝑘 = 𝑖. 𝑛 𝑗 +𝑛 𝑖. 𝑛 𝑘 (distributivity of. 𝑛 on +𝑛 ).
23
7) Remainder Arithmetic :
Lemma 7.3: Let 𝑛 be a positive integer numbersuch that 𝑛 ≥ 1. In ℤ𝑛 , we have:
1) 𝑟𝑒𝑚 𝑖 + 𝑗, 𝑛 = 𝑟𝑒𝑚 𝑖, 𝑛 +𝑛 𝑟𝑒𝑚(𝑗, 𝑛).
2) 𝑟𝑒𝑚 𝑖. 𝑗, 𝑛 = 𝑟𝑒𝑚 𝑖, 𝑛 .𝑛 𝑟𝑒𝑚(𝑗, 𝑛).
Definition 7.4: The multiplicative inverse of a non zero number 𝑥 is another number 𝑥 −1 such
that: 𝑥. 𝑥 −1 = 1 = 𝑥 −1 . 𝑥.
1 1
For example, 3.3−1 = 3. = 1 = 3−1 . 3 = . 3.
3 3

From now on, when we say “inverse,” we mean multiplicative (not relational) inverse.
Over the ring ℤ𝑛 , things get a little more complicated. For example, 2 is a multiplicative inverse
of 8 in ℤ15 , since 2 . 8 = 1(ℤ15 ) ( That is, 2 .15 8 = 1). On the other hand, 3 does not have a
multiplicative inverse in ℤ15 .
24
7) Remainder Arithmetic :
Definition 7.5: Integers that have no prime factor in common are called relatively prime.
This is the same as having no common divisor (prime or not) greater than 1. It’s also equivalent
to saying gcd 𝑎, 𝑏 =1.
For example, 8 and 15 are relatively prime, since gcd 8, 15 =1. On the other hand, 3 and 15 are
not relatively prime, since gcd 3, 15 =3 . This turns out to explain why 8 has an inverse over
ℤ15 and 3 does not.
Lemma 7.6: Let 𝑛 be a positive integer number such that 𝑛 ≥ 1. If 𝑘 ∈ {0,1,2,…, 𝑛 − 1} is
relatively prime to 𝑛, then 𝑘 has an inverse in ℤ𝑛 .
Lemma 7.7: Let 𝑛 be a positive integer number such that 𝑛 ≥ 1. If 𝑖 and 𝑗 are both inverses of
𝑘 in ℤ𝑛 , then 𝑖 = 𝑗 .
Definition 7.8: A number 𝑘 is called cancellable in ℤ𝑛 , if and only if 𝑘. 𝑎 = 𝑘. 𝑏 implies
𝑎 = 𝑏, for all 𝑎, 𝑏 ∈ {0,1,2,…, 𝑛 − 1}.
Lemma 7.9: If 𝑘 has an inverse in ℤ𝑛 , then it is cancellable.
25
8) Turing’s Code (Version 2.0):
Definition 8.1: (Turing’s Code (Version 2.0)) Let’s consider an alternative interpretation of
Turing’s code by using conventional arithmetic instead of modular arithmetic. As follows:
Beforehand: The sender and receiver agree on a large number 𝑛, which may be made public.
(This will be the modulus for all our arithmetic.) As in Version 1.0, they also agree that some
prime number 𝑘 < 𝑛 will be the secret key.
Encryption: As in Version 1.0, the message 𝑚 should be another prime in {0,1,2,…, 𝑛 − 1}.
The sender encrypts the message 𝑚 to produce 𝑚 by computing 𝑚. 𝑘, but this time modulo 𝑛 :
𝑚=
ෝ 𝑚. 𝑘. (ℤ𝑛 ) ( That is, 𝑚=
ෝ 𝑚. 𝑛 𝑘).
Decryption: The decryption step is a problem. We might hope to decrypt in the same way as
before by dividing the encrypted message 𝑚
ෝ by the key 𝑘. The difficulty is that 𝑚.

The difficulty is that 𝑚
ෝ is the remainder when 𝑚. 𝑘 is divided by 𝑛. So dividing 𝑚
ෝ by 𝑘 might
not even give us an integer. This decoding difficulty can be overcome with a better
understanding of when it is ok to divide by 𝑘 in modular arithmetic.
26
9) Euler’s Theorem:
Definition 9.1: Let 𝑛 be a positive integer numbersuch that 𝑛 ≥ 1. Define
𝜙 𝑛 = The number of integers in {0,1,2,…, 𝑛 − 1} that are relatively prime to 𝑛.
This function 𝜙 is known as Euler’s 𝜙 function.
Theorem 9.2: (Euler’s Theorem) If 𝑛 and 𝑘 are relatively prime, then
𝑘 𝜙 𝑛 ≡ 1 𝑚𝑜𝑑 𝑛
Things get simpler when we rephrase Euler’s Theorem in terms of ℤ𝑛 .
Lemma 9.3: (Euler’s Theorem) If 𝑝 and 𝑞 are primes such that 𝑝 ≠ 𝑞, then
𝜙 𝑝𝑞 ≡ 𝑝 − 1 𝑞 − 1 .
Theorem 9.4: (Fermat’s Little Theorem) Suppose 𝑝 is a prime and 𝑘 is not a multiple of 𝑝.
Then, 𝑘 𝑝−1 ≡ 1 𝑚𝑜𝑑 𝑝 .
Theorem 9.5: 1) If 𝑝 is a prime, then 𝜙 𝑝𝑘 ≡ 𝑝𝑘 − 𝑝𝑘 − 1, for 𝑘 ≥ 1.
2) If 𝑎 and 𝑏 are relatively prime, then 𝜙 𝑎𝑏 ≡ 𝜙 𝑎 𝜙 𝑏 .
For example, 𝜙 300 = 𝜙 22 . 3. 52 = 𝜙 22 ). 𝜙(3). 𝜙(52 = 22 − 21 31 − 30 52 − 51 =80.
27
10) RSA Public Key Encryption:
Definition 10.1: (The RSA Cryptosystem)

Beforehand: The Receiver creates a public key and a private key as follows.

1) Generate two distinct primes, 𝑝 and 𝑞 . These are used to generate the private key, and they
must be kept hidden.

2) Let 𝑛 = 𝑝𝑞.

3) Select an integer 𝑒 ∈ {0,1,2,…, 𝑛 − 1} such that gcd 𝑒, 𝑝 − 1 𝑞 − 1 = 1. The public key


is the pair 𝑒, 𝑛 This should be distributed widely.

4) Let the private key 𝑑 ∈ {0,1,2,…, 𝑛 − 1} be the inverse of 𝑒 in the ring ℤ𝑛 =ℤ 𝑝−1 𝑞−1 . This
private key can be found using the Pulverizer. The private key 𝑑 should be kept hidden.
28
10) RSA Public Key Encryption:
Encoding: To transmit a message 𝑚 ∈ {0,1,2,…, 𝑛 − 1} to Receiver, a Sender uses the public
ෝ 𝑚𝑒 (ℤ𝑛 ).
key to encrypt 𝑚 into a numerical message: 𝑚=
The Sender can then publicly transmit 𝑚
ෝ to the Receiver.
Decoding: The Receiver decrypts message 𝑚 ෝ back to message 𝑚 using the private key:
𝑚=𝑚 ෝ 𝑑 (ℤ𝑛 ).
Example 10.2: Identify two sets of public and private keys using the RSA algorithm when 𝑝=17
and 𝑞=11.
1) Calculate 𝑛 = 𝑝𝑞 = 17 * 11 = 187.
2) Calculate 𝜙 𝑛 = (𝑝 − 1)(𝑞 − 1) = 16 * 10 = 160.
3) Select e such that e is relatively prime to 𝜙 𝑛 = 160 and less than 𝜙 𝑛 ; we choose 𝑒 = 7.
4) Determine 𝑑 such that 𝑑𝑒 ≡ 1 (mod 160) and 𝑑 < 160. The correct value is 𝑑 = 23,
because 23 * 7 = 161 = (1 * 160) + 1; 𝑑 can be calculated using the extended Euclid’s
algorithm.
29
10) RSA Public Key Encryption:
5) The resulting keys are: public key 𝑃𝑈 = {7, 187} and private key 𝑃𝑅 = {23, 187}.
The example shows the use of these keys for a plaintext input of 𝑀 = 88.
For encryption, we need to calculate 𝐶 ≡ 887 mod 187.
887 𝑚𝑜𝑑 187 = 884 𝑚𝑜𝑑 187 × 882 𝑚𝑜𝑑 187 × (881 𝑚𝑜𝑑 187)
881 𝑚𝑜𝑑 187 = 88
882 𝑚𝑜𝑑 187=7744 𝑚𝑜𝑑 187 = 77
884 𝑚𝑜𝑑 187=59969536 𝑚𝑜𝑑 187 = 132
887 𝑚𝑜𝑑 187 = (88 × 77 × 132)𝑚𝑜𝑑 187=894432 𝑚𝑜𝑑 187 = 11.
For decryption, we calculate
𝑀 ≡ 1123 𝑚𝑜𝑑 187 = 111 𝑚𝑜𝑑 187 × 112 𝑚𝑜𝑑 187 × (114 𝑚𝑜𝑑 187) × (118 𝑚𝑜𝑑 187) × (118 𝑚𝑜𝑑 187)
111 𝑚𝑜𝑑 187 = 11
112 𝑚𝑜𝑑 187= 121
114 𝑚𝑜𝑑 187=14641 𝑚𝑜𝑑 187 = 55
118 𝑚𝑜𝑑 187=214358 𝑚𝑜𝑑 187 = 33
1123 𝑚𝑜𝑑 187 = 111 × 112 × 114 × 118 × 118 𝑚𝑜𝑑 187 =79720245 𝑚𝑜𝑑 187 =88.
30
10) RSA Public Key Encryption:
Example 10.3: Identify two sets of public and private keys using the RSA algorithm when 𝑝=3 and 𝑞=11.
1) Calculate 𝑛 = 𝑝𝑞 = 3 * 11 = 33.
2) Calculate 𝜙 𝑛 = (𝑝 − 1)(𝑞 − 1) = 2 * 10 = 20.
3) Select 𝑒 such that e is relatively prime to 𝜙 𝑛 = 20 and less than 𝜙 𝑛 ; we choose 𝑒 = 3.
4) Compute 𝑑 such that 𝑑𝑒 ≡ 1 (mod 20) and 𝑑 < 20.
The correct value is 𝑑 = 7, because 7 * 3 = 21 = (1 * 20) + 1; 𝑑 can be calculated using the extended Euclid’s
algorithm.
𝜙 𝑛 = (𝑝 − 1)(𝑞 − 1) = 2 * 10 = 20.
5) Public key PU = (𝑛, 𝑒) = (33, 3) and Private key PR= (𝑛, 𝑑) = (33, 7).
This is actually the smallest possible value for the modulus 𝑛 for which the RSA algorithm works.
Now say we want to encrypt the message 𝑀 = 7,
𝐶 ≡ 𝑀𝑒 𝑚𝑜𝑑 𝑛 ≡ 73 mod 33 ≡ 343 mod 33 ≡ 13. Hence the ciphertext 𝐶 = 13.
To check decryption we compute
𝑀′ ≡ 𝐶 𝑑 𝑚𝑜𝑑 𝑛 ≡ 137 mod 33= 13(4+2+1) mod 33= 134 . 132 . 131 mod 33= 16× 4× 13= 832 mod 33=7. 31

You might also like