lecture03 - Introduction to Number Theory
lecture03 - Introduction to Number Theory
Network Security
2
Divisibility
3
Properties of Divisibility
• If a | 1, then a = ±1
• If a | b and b | a, then a = ±b
• Any b ≠ 0 divides 0
•If a | b and b | c, then a | c
4
Properties of Divisibility
b = 7; g = 14; h = 63; m = 3; n = 2
7 | 14 and 7 | 63.
To show 7 (3 * 14 + 2 * 63),
we have (3 * 14 + 2 * 63) = 7(3 * 2 + 2 * 9),
and it is obvious that 7 | (7(3 * 2 + 2 * 9)).
5
Division Algorithm
a = qn + r 0 ≤ r < n; q = 𝑎/𝑛
6
Noted that 𝑥 is the largest integer less than or equal to x
7
Greatest Common Divisor (GCD)
8
Greatest Common Divisor (GCD)
9
Greatest Common Divisor (GCD)
8 and 15 are relatively prime because the positive divisors of 8 are 1, 2, 4, and 8,
and the positive divisors of 15 are 1, 3, 5, and 15. So 1 is the only integer on both
lists.
10
Euclidean
• One of the basic techniques
Algorithm of number theory
• Procedure for determining
the greatest common
divisor of two positive
integers
• Two integers are relatively
prime if and only if their
only common positive
integer factor is 1
11
Euclidean Algorithm
12
a=
qub + ry
b= qzritrz
∠
q 3 r2 try
13
Finding the Greatest Common Divisor
14
Finding the Greatest Common Divisor
15
Euclidean Algorithm Example
16
Class Exercises
17
Modular Arithmetic
• The modulus
• If a is an integer and n is a positive integer, we define a mod n to be
the remainder when a is divided by n; the integer n is called the
modulus
• Thus, for any integer a:
𝑎
𝑎 = 𝑞𝑛 + 𝑟, 0 ≤ 𝑟 < 𝑛; 𝑞 =
𝑎 𝑛
𝑎= × 𝑛 + 𝑎 𝑚𝑜𝑑 𝑛
𝑛
𝒂 𝒎𝒐𝒅 𝒏 = 𝒓 = 𝒂 − 𝒒𝒏
• Congruent modulo n
• Two integers a and b are said to be congruent modulo n if
(a mod n) = (b mod n)
19
Properties of Congruence
23 ≡ 8 (mod 5) because 23 - 8 = 15 = 5 * 3
- 11 ≡ 5 (mod 8) because - 11 - 5 = - 16 = 8 * (- 2)
81 ≡ 0 (mod 27) because 81 - 0 = 81 = 27 * 3
20
Modular Arithmetic
•Modular arithmetic exhibits the following properties:
1. [(a mod n) + (b mod n)] mod n = (a + b) mod n
11 mod 8 = 3; 15 mod 8 = 7
[(11 mod 8) + (15 mod 8)] mod 8 = 10 mod 8 = 2
(11 + 15) mod 8 = 26 mod 8 = 2
[(11 mod 8) - (15 mod 8)] mod 8 = - 4 mod 8 = 4
(11 - 15) mod 8 = - 4 mod 8 = 4
[(11 mod 8) * (15 mod 8)] mod 8 = 21 mod 8 = 5
(11 * 15) mod 8 = 165 mod 8 = 5
22
Arithmetic Modulo 8
23
Multiplication Modulo 8
24
Properties of Modular Arithmetic for Integers in Zn
25
Class Exercises
26
Multiplicative Inverse
• A multiplicative inverse or reciprocal for a number 𝒙 mod n,
denoted by 𝑥 mod n, is a number which when multiplied by 𝑥
yields the multiplicative identity, 1.
a -
b Co -
prime
29
30
Euclidean Algorithm Revisited
31
Euclidean Algorithm Revisited
Euclid(a,b)
if (b=0) then return a;
else return Euclid(b, a mod b);
32
Euclidean Algorithm vs. Extended EA
33
Example
34
Extended Euclidean Algorithm
35
Extended Euclidean Algorithm
36
Extended Euclidean Algorithm
ri = ri-2 - qiri-1
xi = xi-2 - qixi-1
yi = yi-2 - qiyi-1
37
Extended Euclidean Algorithm
d = rn = axn + byn 38
Extended Euclidean Algorithm Example
Let us use a = 1759 and b = 550 and solve for 1759x + 550y = gcd(1759,
550). The results are shown in Table 2.4. Thus, we have 1759 * (-111) +
550 * 355 = -195249 + 195250 = 1.
39
Prime Numbers
• Prime numbers only have divisors of 1 and itself.
• They cannot be written as a product of other numbers
• Numbers are said to be relatively prime (or co-prime) iff they only
have a common divisor of 1 (only share a same divisor of 1).
41
Fermat's Theorem
Example:
Try :
13^(3-1) ≡ 1 (mod 3)
15^(3-1) ≡ 0 (mod 3) --- a should not be divisible by p
42
2
x =
4x
Class Exercises x 4 (x )
≈
.
a 1
p Co -
≡ 1 mod y
. a ,
p not co -
三 O ( mod 5 )
43
Class Exercises
44
Euler’s Totient Function ø(n)
0
Euler’s totient function, written as ø(n), is defined as the number of positive
0integers less than n and relatively prime to n. By convention, ø(n)=1.
Example:
(21) = 12
Co-primes are:
1, 2, 4, 5, 8, 10,
11, 13, 16, 17, 19, 20
Total: 12 of them.
一
Property of Euler’s Totient Function ø(n)
Example:
48
Testing for Primality - Miller-Rabin Algorithm
• For many cryptographic algorithms, it is necessary to select one or more
very large prime numbers at random.
• Thus, we are faced with the task of determining whether a given large
number is prime.
• There is no simple yet efficient means of accomplishing this task.
• We present one attractive and popular algorithm.
• Note that this algorithm yields a number that is not necessarily a prime.
49
Testing for Primality - Miller-Rabin Algorithm
•A composite number is a positive integer that can be formed by multiplying two
smaller positive integers.
•Typically used to test a large number for primality
•Algorithm is:
TEST (n)
4. • for j = 0 to k – 1 do
j
5. • if (a2 q mod n = n – 1) then return (“inconclusive") ;
6. • return (“composite") ;
50
Example
• If n = 29, is a prime number
• (n – 1) = 28 = 2^2(7) k = 2, q = 7
• Try a = 10
• 10^7 mod 29 = 17
• 10^(2*7) mod 29 = 28
• Try a = 2
• 2^7 mod 29 = 12
• 2^(2*7) mod 29 = 28
• All inconclusive results
52
Chinese Remainder Theorem (CRT)
•Believed to have been discovered by the Chinese mathematician
Sun-Tsu in around 100 A.D.
•One of the most useful results of number theory
•Says it is possible to reconstruct integers in a certain range from
their residues modulo a set of pairwise relatively prime moduli
53
CRT-韩信点兵
相传,楚汉争霸之时,韩信率1500名将士与楚军交战败退,
退往山上,这时候敌军率五百骑杀奔而来,韩信便急速点
兵迎敌。
韩信命令士兵3人一排,结果多出2名;接着命令士兵5人
一排,结果多出3名;他又命令士兵7人一排,结果又多出
2名。
韩信马上算出,军中还剩1073人,而敌人不足五百,而且
居高临下、以众击寡,于是率军杀得敌方大败而逃。
*在南北朝时期,《孙子算经》记述了上面这个问题。《孙子算 54
经》的作者和《孙子兵法》的孙武是不同的人
CRT-Math modeling
a1 ≡ 2 (mod 3)
a2 ≡ 3 (mod 5)
a3 ≡ 2 (mod 7)
Let ↑ 累乘
𝑀= 𝑚
mi 两两互质
where mi are pairwise relatively prime.
最好都为质数
That is, gcd(mi, mj) = 1 for 1 … i, j … k, and i ≠ j. We can represent
0
56
Normal Form to CRT Form
𝑀= 𝑚
𝐴 ↔ (𝑎 , 𝑎 , … , 𝑎 )
58
CRT Arithmetic
59
CRT Arithmetic Example
60
CRT Arithmetic Example
61
Primitive Root of Unity Modulus 𝑝
63
Assignment 3
cryptography-and-network-security_-principles-and-
practice-7th-global-edition.pdf
64