Introduction To Number Theory
Introduction To Number Theory
Introduction To Number Theory
Arithmetic
• Consists of a set of Integers
and operations on it.
Integer Division
• If b|a and b≠0, then a=q*b; where a,b,q ∈ Z
• If b∤a and b≠0, then a=q*b+r; where a,b,q,r ∈ Z
• If b|a and a|b, then a=±b.
Properties of • If b|1, then b=±1.
Integer • If a|b and b|c, then a|c.
Division • If a|b and a|c, then a|(m*b+n*c), where a, b,
c, m, n ∈ Z.
MODULAR ARITHMETIC
Modular Arithmetic
• For a=q*b+r, a mod b = r; where a, b, q, r ∈ Z.
• Zn = {0, 1, 2, 3, 4, …… (n-1)}
Modular
Arithmetic
(Examples)
• 27 mod 5 = 2
• 36 mod 7 = 1
• -13 mod 6 = 5
• -29 mod 12 = 7
Basic
• If a,b ∈ Zn, then (a+b) mod n = c ∈ Zn
Operations • If a,b ∈ Zn, then (a-b) mod n = c ∈ Zn
in Modular • If a,b ∈ Zn, then (a*b) mod n = c ∈ Zn
Arithmetic
Basic • (17+19) mod 23 = 13 ∈ Z23
Operations in • (3-5) mod 6 = 4 ∈ Z6
• (13*14) mod 15 = 2 ∈ Z15
Modular
• (8*9) mod 13 = 7 ∈ Z13
Arithmetic
(Examples)
Properties of Modular Arithmetic
(28-16) mod 8 = [(28 mod 8) - (16 mod 8)] mod 8 = (4-0) mod 8 = 4 ∈ Z8
(23*25) mod 20 = [(23 mod 20)*(25 mod 20)] mod 20 = (3*5) mod 20 = 15 ∈ Z20
Modular Additive Inverse
For a,b ∈ Zn, b is the additive inverse of a if (a+b) ≡ 0 (mod n)
Additive Inverse pairs of Z10 = {(0,0), (1,9), (2,8), (3,7), (4,6), (5,5)}
Additive Inverse pairs of Z11 = {(0,0), (1,10), (2,9), (3,8), (4,7), (5,6)}
Modular Multiplicative Inverse
Prime
to negative numbers as well.
• In Cryptography, large primes are required for algorithms like
RSA, Diffie Hellman, etc.
Numbers
Prime Factorization
• Expressing a positive composite number as a product of primes.
• Prime factorization of a number is harder than multiplying the
primes to generate the number.
• 10 = 2 * 5
• 100 = 22 * 52
• 1000 = 23 * 53
• 120 = 23 * 3 * 5
• 5040 = 24 * 32 * 5 * 7
• In Cryptography, typically only
positive numbers are used.
• If c|a and c|b, the GCD(a, b)=c;
where a,b,c ∈ N.
a b
48 18
18 12
12 6
6 0
GCD (198, 121) = ?
a b
198 121
121 77
77 44
44 33
33 11
11 0
GCD (584, 248) = ?
a b
584 248
248 88
88 72
72 16
16 8
8 0
GCD (66348, 18042) = ?
a b
66348 18042
18042 12222
12222 5820
5820 582
582 0
GCD (868, 795) = ?
a b
868 795
795 73
73 65
65 8
8 1
1 0
EXTENDED EUCLIDEAN
ALGORITHM (EEA)
EEA for gcd(a,b)=d
EEA(a, b)
• Here d=a*x+b*y; where
{
x,y∈Z.
u1=1, u2=0, v1=0, v2=1;
while(b≠0)
{
q=a/b; r=a mod b; u=u1-q*u2; v=v1-q*v2; a=b; b=r;
u1=u2; u2=u; v1=v2; v2=v;
}
d=a; x=u1; y=v1;
return(d, x, y)
}
Calculate GCD(48,18), x, y
q a b r u1 u2 u v1 v2 v
2 48 18 12 1 0 1 0 1 -2
1 18 12 6 0 1 -1 1 -2 3
2 12 6 0 1 -1 3 -2 3 -8
6 0 -1 3 3 -8
q a b r u1 u2 u v1 v2 v
1 848 596 252 1 0 1 0 1 -1
2 596 252 92 0 1 -2 1 -1 3
2 252 92 68 1 -2 5 -1 3 -7
1 92 68 24 -2 5 -7 3 -7 10
2 68 24 20 5 -7 19 -7 10 -27
1 24 20 4 -7 19 -26 10 -27 37
5 20 4 0 19 -26 149 -27 37 -212
q a b r u1 u2 u v1 v2 v
2 165 68 29 1 0 1 0 1 -2
2 68 29 10 0 1 -2 1 -2 5
2 29 10 9 1 -2 5 -2 5 -12
1 10 9 1 -2 5 -7 5 -12 17
9 9 1 0 5 -7 68 -12 17 -165
1 0 -7 68 17 -165
• GCD(165,68) = 1 = 165*(-7)+68*(17)
• Hence, MI(165) mod 68 = -7 mod 68 = 61
MI(485) mod 812 = ?
q a b r v1 v2 v
1 812 485 327 0 1 -1
• MI(485) mod 812 = 221
1 485 327 158 1 -1 2
2 327 158 11 -1 2 -5
14 158 11 4 2 -5 72
2 11 4 3 -5 72 -149
1 4 3 1 72 -149 221
3 3 1 0 -149 221 -812
1 0 221 -812
MI(608) mod 73 = ?
q a b r u1 u2 u
8 608 73 24 1 0 1
3 73 24 1 0 1 -3
24 24 1 0 1 -3 73
1 0 -3 73
4
• 7 mod 20 = 1
• 713 mod 20 = [712 mod 20 * 7 mod 20] mod 20
• 713 mod 20 = (74 mod 20)3 mod 20 * 7 mod 20 = 7
27
13 mod 48 = ?
• 27 = 16+8+2+1
• 132 mod 48 = 25
• 138 mod 48 = (132 mod 48)4 mod 48 = 254 mod 48 = 1
16 8 2 2
• 13 mod 48 = (13 mod 48) mod 48 = 1 mod 48 = 1
• 1327 mod 48 = (1316 mod 48 * 138 mod 48 * 132 mod 48* 13) mod 48 =
(1*1*25*13) mod 48 = 37
239
106 mod 54 = ?
• 239 = 128 + 64 + 32 + 8 + 4 + 2 + 1
• 1062 mod 54 = 4
4 2 2 2
• 106 mod 54 = (106 mod 54) mod 54 = 4 mod 54 = 16
• 1068 mod 54 = (1064 mod 54)2 mod 54 = 162 mod 54 = 40
• 10632 mod 54 = (1068 mod 54)4 mod 54 = 404 mod 54 = 22
64 32 2 2
• 106 mod 54 = (106 mod 54) mod 54 = 22 mod 54 = 52
• 106128 mod 54 = (10664 mod 54)2 mod 54 = 522 mod 54 = 4
• 106239 mod 54 = (106128 mod 54 * 10664 mod 54 * 10632 mod 54 * 1068 mod 54 *
4 2
106 mod 54 * 106 mod 54 * 106) mod 54
239
106 mod 54 = ? (Contd..)
96
• 200 mod 97 = 1
192 96 2 2
• 200 mod 97 = (200 mod 97) mod 97 = 1 mod 97 = 1
1026
3 mod 103 = ?
102
• 3 mod 103 = 1
1020 102 10 10
•3 mod 103 = (3 mod 103) mod 103 = 1 mod 13 = 1
1026 1020 6
•3 mod 103 = (3 mod 103 * 3 mod 103) mod 103
1026
•3 mod 103 = (1*8) mod 103 = 8
EULER’S THEOREM
Euler Totient Function (ϕ(n))
• n = 105
k
• n-1 = 2 * q
3
• 104 = 2 * 13; where k=3 and q=13
• Select a = 2
• aq mod n = 213 mod 105 = 2
• a2*q mod n = (aq mod n)2 mod n = 22 mod 105 = 4
4*q 2*q 2 2
• a mod n = (a mod n) mod n = 4 mod 105 = 16
• Hence, 105 is composite
MLA on 35
• n = 35
• n-1 = 2k * q i.e. 34 = 21 * 17; where k=1 and q=17
• Select a=2
• aq mod n = 217 mod 35 = 32
• Hence 35 is composite
MLA on 233
• n = 233
• n-1 = 2k * q i.e. 232 = 23 * 29; where k=3 and q=29
• Select a = 2
• aq mod n = 229 mod 233 = 1
• Hence, 233 is a prime
MLA on 61
• n = 61
• n-1 = 2k * q i.e. 60 = 22 * 15; where k=2 and q=15
• Select a = 2
• aq mod n = 215 mod 61 = 11
• a2*q mod n = (aq mod n)2 mod n = 112 mod 61 = 60
• Hence, 61 is prime
MLA on 241
• n = 241
• n-1 = 2k * q i.e. 240 = 24 * 15; where k=4 and q=15
• Select a = 2
• aq mod n = 215 mod 241 = 233
• a2*q mod n = (aq mod n)2 mod n = 2332 mod 241 = 64
4*q 2*q 2 2
• a mod n = (a mod n) mod n = 64 mod 241 = 240
• Hence, 241 is prime
Probabilistic Considerations for MLA
• a1 = 1, a2 = 2, a3 = 3, m1 = 5, m2 = 6, m3 = 7;
• M = m1*m2*m3 = 5*6*7 = 210
• M1 = M/m1 = 210/5 = 42
• M2 = M/m2 = 210/6 = 35
• M3 = M/m3 = 210/7 = 30
CRT Example 1 (Contd..)
• N1 = MI(M1) (mod m1)
• N1 = MI(42) (mod 5)
q a b r u1 u2 u
8 42 5 2 1 0 1
2 5 2 1 0 1 -2
2 2 1 0 1 -2 5
1 0 -2 5
• N1 = -2 (mod 5) = 3
CRT Example 1 (Contd..)
• N2 = MI(M2) (mod m2)
• N2 = MI(35) (mod 6)
q a b r u1 u2 u
5 35 6 5 1 0 1
1 6 5 1 0 1 -1
5 5 1 0 1 -1 6
1 0 -1 6
• N2 = -1 mod 6 = 5
CRT Example 1 (Contd..)
• N3 = MI(M3) (mod m3)
• N3 = MI(30) (mod 7)
q a b r u1 u2 u
4 30 7 2 1 0 1
3 7 2 1 0 1 -3
2 2 1 0 1 -3 7
1 0 -3 7
• N3 = -3 mod 7 = 4
CRT Example 1 (Contd..)
• x = (a1*M1*N1 + a2*M2*N2 + a3*M3*N3) mod M
• x = (1*42*3 + 2*35*5 + 3*30*4) mod 210 = 206
CRT Example 2:-
• Solve for x:-
q a b r u1 u2 u
353 1768 5 3 1 0 1
1 5 3 2 0 1 -1
1 3 2 1 1 -1 2
2 2 1 0 -1 2 -5
1 0 2 -5
• N1 = 2
CRT Example 2 (Contd..)
• N2 = MI(M2) (mod m2)
• N2 = MI(1105) (mod 8)
q a b r u1 u2 u
138 1105 8 1 1 0 1
8 8 1 0 0 1 -8
1 0 1 -8
• N2 = 1
CRT Example 2 (Contd..)
• N3 = MI(M3) (mod m3)
• N3 = MI(680) (mod 13)
q a b r u1 u2 u
52 680 13 4 1 0 1
3 13 4 1 0 1 -3
4 4 1 0 1 -3 13
1 0 -3 13
• N3 = -3 mod 13 = 10
CRT Example 2 (Contd..)
• N4 = MI(M4) (mod m4)
• N4 = MI(520) (mod 17)
q a b r u1 u2 u
30 520 17 10 1 0 1
1 17 10 7 0 1 -1
1 10 7 3 1 -1 2
2 7 3 1 -1 2 -5
3 3 1 0 2 -5 17
1 0 -5 17
• N4 = -5 mod 17 = 12
CRT Example 2 (Contd..)
• x = (a1*M1*N1 + a2*M2*N2 + a3*M3*N3 + a4*M4*N4) mod M
• x = (3*1768*2 + 4*1105*1 + 11*680*10 + 6*520*12) mod 8840 = 3508
DISCRETE LOGARITHMS
Order of an Integer a mod n
• Ordern(a)= smallest natural number k such that ak mod n = 1; where
GCD(a,n)=1, 1≤a<n, and 1≤k≤ϕ(n).
• Order7(2) = 3
• Order5(3) = 4
• Order15(8) = 4
• Order9(8) = 2
• Order8(1) = 1
Ord11(8) = ?
• GCD(8,11) = 1
• ϕ(11) = 10
1
• 8 mod 11 = 8
2
• 8 mod 11 = 9
3
• 8 mod 11 = 6
4
• 8 mod 11 = 4
5
• 8 mod 11 = 10
6
• 8 mod 11 = 3
7
• 8 mod 11 = 2
8
• 8 mod 11 = 5
9
• 8 mod 11 = 7
10
• 8 mod 11 = 1
• Therefore Ord11(8) = 10
Ord9(4) = ?
• GCD(4,9) = 1
• 41 mod 9 = 4
• 42 mod 9 = 7
3
• 4 mod 9 = 1
• Therefore Ord9(4) = 3
Ord12(8) = ?
• GCD(8,12) = 4.
• Therefore Ord12(8) doesn’t exist.
Primitive Roots of n
• ‘a’ is a primitive root of n if Ordn(a) = ϕ(n).
α
• All αn don’t have primitive roots. For n to have primitive roots, n=2, 4, p ,
2*p , where p is any odd prime, α is a natural number
• Examples of natural numbers having primitive roots are 2,3,4,5,6,7,9,10,11,
etc.
• Examples of natural numbers which don’t have primitive roots are 8, 12, 15,
etc.
• Primitive roots of 7 are 3 and 5.
• Primitive roots of 5 are 2 and 3.
Primitive Roots of 11
• ϕ(11) = 10
a=1:-
1
• 1 mod 11
• Ord11(1) = 1
• Hence 1 is not a primitive root of 11
a=2:-
1
• 2 mod 11 = 2
2
• 2 mod 11 = 4
3
• 2 mod 11 = 8
4
• 2 mod 11 = 5
5
• 2 mod 11 = 10
6
• 2 mod 11 = 9
Primitive Roots of 11 (Contd..)
• 27 mod 11 = 7
• 28 mod 11 = 3
• 29 mod 11 = 6
• 210 mod 11 = 1
• Ord11(2) = 10
• Hence 2 is a primitive root of 11
a=3:-
• 31 mod 11 = 3
• 32 mod 11 = 9
• 33 mod 11 = 5
• 34 mod 11 = 4
• 35 mod 11 = 1
• Ord11(3) = 5
• Hence, 3 is not a primitive root of 11
Primitive Roots of 11 (Contd..)
a=4:-
1
• 4 mod 11 = 4
2
• 4 mod 11 = 5
3
• 4 mod 11 = 9
4
• 4 mod 11 = 3
5
• 4 mod 11 = 1
• Ord11(4) = 5
• Hence 4 is not a primitive root of 11
a=5:-
• Ord11(5) = 5
• Hence , 5 is not a primitive root of 11.
Primitive Roots of 11 (Contd..)
a=6:-
• Ord11(6) = 10
• Hence , 6 is a primitive root of 11.
a=7:-
• Ord11(7) = 10
• Hence , 7 is a primitive root of 11.
a=8:-
• Ord11(8) = 10
• Hence , 8 is a primitive root of 11.
Primitive Roots of 11 (Contd..)
a=9:-
• Ord11(9) = 5
• Hence , 9 is not a primitive root of 11.
a=10:-
• Ord11(10) = 2
• Hence , 10 is not a primitive root of 11.
x
Calculate the Discrete logarithm x, where 3 mod 7 = 4:-
• GCD(4,7) = 1
• Ord7(3) = 6;
• Min value of x = 4.
• Therefore, x = 4+6*k, where k ∈ W.
x
Solve for x:- 5 (mod 18) = 11
• GCD(11,18) = 1
• Ord18(5) = 6
• Min value of x = 5
• Therefore, x = 5+6*k, where k ∈ W.