Chapter 4. Number Theory and Cryptography
Chapter 4. Number Theory and Cryptography
Contents
Contents
Contents
Division
Division
Division
Division
Division
Division
An algorithm to find k
An algorithm to find k
1. Let i = 0
An algorithm to find k
1. Let i = 0
2. If (i + 1)d > n then k = i
An algorithm to find k
1. Let i = 0
2. If (i + 1)d > n then k = i
3. Othersewise go back to step 2. with i is replaced by
i +1
An algorithm to find k
1. Let i = 0
2. If (i + 1)d > n then k = i
3. Othersewise go back to step 2. with i is replaced by
i +1
An algorithm to find k
1. Let i = 0
2. If (i + 1)d > n then k = i
3. Othersewise go back to step 2. with i is replaced by
i +1
Notes.
• Let r = n − kd . Then we have n = kd + r. The integers
k and r are called the quotient (thương) and the
remainder (số dư) in the division of n by d.
An algorithm to find k
1. Let i = 0
2. If (i + 1)d > n then k = i
3. Othersewise go back to step 2. with i is replaced by
i +1
Notes.
• Let r = n − kd . Then we have n = kd + r. The integers
k and r are called the quotient (thương) and the
remainder (số dư) in the division of n by d.
• Thus the above algorithm allows us to find the
quotient and the remainder of the division algorithm
(thuật toán chia).
Lai Văn Phút Chapter 4. Number Theory and Cryptography
The Integers and Division Integers and Algorithms Primes and Greatest Common Divisors Problems
a = dq + r, 0 ≤ r < d
a = dq + r, 0 ≤ r < d
a = dq + r, 0 ≤ r < d
a = dq + r, 0 ≤ r < d
a = dq + r, 0 ≤ r < d
a = dq + r, 0 ≤ r < d
a = dq + r, 0 ≤ r < d
Solution
Quizz
Quizz
Ans: b
Lai Văn Phút Chapter 4. Number Theory and Cryptography
The Integers and Division Integers and Algorithms Primes and Greatest Common Divisors Problems
Quizz
Quizz
Ans: d
6|(17 − 5)?
Solution
Theorem
Theorem
Theorem
Theorem
Theorem
Theorem
Example.
Example.
1. What is the secret message produced from the
message “MEET YOU IN THE PARK” using the Caesar
cipher (k=3)?
Example.
Example.
1. What is the secret message produced from the
message “MEET YOU IN THE PARK” using the Caesar
cipher (k=3)?
2. Decrypt the ciphertext message “LEWLYPLUJL PZ H
NYLHA ALHJOLY” that was encrypted with the shift
cipher with shift k = 7.
Example.
Example.
1. What is the secret message produced from the
message “MEET YOU IN THE PARK” using the Caesar
cipher (k=3)?
2. Decrypt the ciphertext message “LEWLYPLUJL PZ H
NYLHA ALHJOLY” that was encrypted with the shift
cipher with shift k = 7.
3. What letter replaces the letter K when the function
f (p) = (7p + 3)mod26 is used for encryption?
Solution
Solution
Solution
Solution
Solution
Solution
Solution
Solution
Solution
Solution
Solution
Solution
Quizz
Quizz
Ans: d
Notes.
• a: Multiplier (nhân tử) (2 ≤ a < m)
Notes.
• a: Multiplier (nhân tử) (2 ≤ a < m)
• c: Increment (số gia) (0 ≤< m)
Notes.
• a: Multiplier (nhân tử) (2 ≤ a < m)
• c: Increment (số gia) (0 ≤< m)
• x0 : seed (hạt giống) (0 ≤ x0 < m)
Notes.
• a: Multiplier (nhân tử) (2 ≤ a < m)
• c: Increment (số gia) (0 ≤< m)
• x0 : seed (hạt giống) (0 ≤ x0 < m)
• m: modulus (mođun)
Notes.
• a: Multiplier (nhân tử) (2 ≤ a < m)
• c: Increment (số gia) (0 ≤< m)
• x0 : seed (hạt giống) (0 ≤ x0 < m)
• m: modulus (mođun)
Notes.
• a: Multiplier (nhân tử) (2 ≤ a < m)
• c: Increment (số gia) (0 ≤< m)
• x0 : seed (hạt giống) (0 ≤ x0 < m)
• m: modulus (mođun)
Example.(Random numbers from 0 to 8) Find the
sequence of pseudorandom numbers generated by the
linear congruential method with modulus m = 9, multiplier
a = 7, increment c = 4, and seed x0 = 3.
Notes.
• a: Multiplier (nhân tử) (2 ≤ a < m)
• c: Increment (số gia) (0 ≤< m)
• x0 : seed (hạt giống) (0 ≤ x0 < m)
• m: modulus (mođun)
Example.(Random numbers from 0 to 8) Find the
sequence of pseudorandom numbers generated by the
linear congruential method with modulus m = 9, multiplier
a = 7, increment c = 4, and seed x0 = 3.m = 9, a = 7, c =
4, x0 = 3 =⇒ xn+1 = 7xn + 4
Lai Văn Phút Chapter 4. Number Theory and Cryptography
The Integers and Division Integers and Algorithms Primes and Greatest Common Divisors Problems
Notes.
• a: Multiplier (nhân tử) (2 ≤ a < m)
• c: Increment (số gia) (0 ≤< m)
• x0 : seed (hạt giống) (0 ≤ x0 < m)
• m: modulus (mođun)
Example.(Random numbers from 0 to 8) Find the
sequence of pseudorandom numbers generated by the
linear congruential method with modulus m = 9, multiplier
a = 7, increment c = 4, and seed x0 = 3.m = 9, a = 7, c =
4, x0 = 3 =⇒ xn+1 = 7xn + 4 =⇒ x1 , x2 , ...
Lai Văn Phút Chapter 4. Number Theory and Cryptography
The Integers and Division Integers and Algorithms Primes and Greatest Common Divisors Problems
Solution.
Example.
H (k ) = k mod m
Using in searching data in memory
• k: data searched,
H (k ) = k mod m
Using in searching data in memory
• k: data searched,
• m: memory block.
H (k ) = k mod m
Using in searching data in memory
• k: data searched,
• m: memory block.
H (k ) = k mod m
Using in searching data in memory
• k: data searched,
• m: memory block.
Example. Find the memory locations assigned by the
hashing function h(k ) = k mod 111 to the records of
customers with Social Security numbers 064212848 and
037149212.
H (k ) = k mod m
Using in searching data in memory
• k: data searched,
• m: memory block.
Example. Find the memory locations assigned by the
hashing function h(k ) = k mod 111 to the records of
customers with Social Security numbers 064212848 and
037149212.
h(064212848) = 064212848 mod 111 = 14
H (k ) = k mod m
Using in searching data in memory
• k: data searched,
• m: memory block.
Example. Find the memory locations assigned by the
hashing function h(k ) = k mod 111 to the records of
customers with Social Security numbers 064212848 and
037149212.
h(064212848) = 064212848 mod 111 = 14
H (k ) = k mod m
Using in searching data in memory
• k: data searched,
• m: memory block.
Example. Find the memory locations assigned by the
hashing function h(k ) = k mod 111 to the records of
customers with Social Security numbers 064212848 and
037149212.
h(064212848) = 064212848 mod 111 = 14→memory
location 14.
h(037149212) = 037149212 mod 111 = 65
H (k ) = k mod m
Using in searching data in memory
• k: data searched,
• m: memory block.
Example. Find the memory locations assigned by the
hashing function h(k ) = k mod 111 to the records of
customers with Social Security numbers 064212848 and
037149212.
h(064212848) = 064212848 mod 111 = 14→memory
location 14.
h(037149212) = 037149212 mod 111 = 65
H (k ) = k mod m
Using in searching data in memory
• k: data searched,
• m: memory block.
Example. Find the memory locations assigned by the
hashing function h(k ) = k mod 111 to the records of
customers with Social Security numbers 064212848 and
037149212.
h(064212848) = 064212848 mod 111 = 14→memory
location 14.
h(037149212) = 037149212 mod 111 = 65 → memory
location 65.
Lai Văn Phút Chapter 4. Number Theory and Cryptography
The Integers and Division Integers and Algorithms Primes and Greatest Common Divisors Problems
Representations of Integers
Representations of Integers
Representations of Integers
Representations of Integers
Representations of Integers
Representations of Integers
Representations of Integers
Representations of Integers
Representations of Integers
Representations of Integers
Representations of Integers
Representations of Integers
Examples.
Examples.
Examples.
Sol a.
241 = 120.2 + 1
Sol a.
241 = 120.2 + 1
= 60.22 + 1
Sol a.
241 = 120.2 + 1
= 60.22 + 1
= 30.23 + 1
Sol a.
241 = 120.2 + 1
= 60.22 + 1
= 30.23 + 1
= 15.24 + 1
Sol a.
241 = 120.2 + 1
= 60.22 + 1
= 30.23 + 1
= 15.24 + 1
= (7.2 + 1).24 + 1 =
7.25 + 24 + 1
Sol a.
241 = 120.2 + 1
= 60.22 + 1
= 30.23 + 1
= 15.24 + 1
= (7.2 + 1).24 + 1 =
7.25 + 24 + 1
= (3.2 + 1).25 + 24 + 1 =
3.26 + 25 + 24 + 1
Sol a.
241 = 120.2 + 1
= 60.22 + 1
= 30.23 + 1
= 15.24 + 1
= (7.2 + 1).24 + 1 =
7.25 + 24 + 1
= (3.2 + 1).25 + 24 + 1 =
3.26 + 25 + 24 + 1
(1.2 + 1).26 + 25 + 24 + 1 =
27 + 26 + 25 + 24 + 1
Sol a.
241 = 120.2 + 1
= 60.22 + 1
= 30.23 + 1
= 15.24 + 1
= (7.2 + 1).24 + 1 =
7.25 + 24 + 1
= (3.2 + 1).25 + 24 + 1 =
3.26 + 25 + 24 + 1
(1.2 + 1).26 + 25 + 24 + 1 =
27 + 26 + 25 + 24 + 1
Sol a.
241 = 120.2 + 1
= 60.22 + 1
= 30.23 + 1
= 15.24 + 1
= (7.2 + 1).24 + 1 =
7.25 + 24 + 1
= (3.2 + 1).25 + 24 + 1 =
3.26 + 25 + 24 + 1
(1.2 + 1).26 + 25 + 24 + 1 =
27 + 26 + 25 + 24 + 1
Thus, (241)10 = 241 = (11110001)2
Sol a.
Sol a.
Sol a.
Sol a.
Sol a.
Sol a.
Sol a.
Sol a.
Sol a.
Sol a.
Solution.
Solution.
Solution.
q = 241 6= 0
k=0: a0 = 241 mod 2 = 1, q = 241 div 2 = 120 6= 0
Solution.
q = 241 6= 0
k=0: a0 = 241 mod 2 = 1, q = 241 div 2 = 120 6= 0
k=1:a1 = 0, q = 60
Solution.
q = 241 6= 0
k=0: a0 = 241 mod 2 = 1, q = 241 div 2 = 120 6= 0
k=1:a1 = 0, q = 60
k=2:a2 = 0, q = 30
Solution.
q = 241 6= 0
k=0: a0 = 241 mod 2 = 1, q = 241 div 2 = 120 6= 0
k=1:a1 = 0, q = 60
k=2:a2 = 0, q = 30
k=3:a3 = 0, q = 15
Solution.
q = 241 6= 0
k=0: a0 = 241 mod 2 = 1, q = 241 div 2 = 120 6= 0
k=1:a1 = 0, q = 60
k=2:a2 = 0, q = 30
k=3:a3 = 0, q = 15
k=4:a4 = 1, q = 7
Solution.
q = 241 6= 0
k=0: a0 = 241 mod 2 = 1, q = 241 div 2 = 120 6= 0
k=1:a1 = 0, q = 60
k=2:a2 = 0, q = 30
k=3:a3 = 0, q = 15
k=4:a4 = 1, q = 7
k=5:a5 = 1, q = 3
Solution.
q = 241 6= 0
k=0: a0 = 241 mod 2 = 1, q = 241 div 2 = 120 6= 0
k=1:a1 = 0, q = 60
k=2:a2 = 0, q = 30
k=3:a3 = 0, q = 15
k=4:a4 = 1, q = 7
k=5:a5 = 1, q = 3
k=6:a6 = 1, 1 = 1
Solution.
q = 241 6= 0
k=0: a0 = 241 mod 2 = 1, q = 241 div 2 = 120 6= 0
k=1:a1 = 0, q = 60
k=2:a2 = 0, q = 30
k=3:a3 = 0, q = 15
k=4:a4 = 1, q = 7
k=5:a5 = 1, q = 3
k=6:a6 = 1, 1 = 1
k=7:a7 = 1, q = 0
Solution.
q = 241 6= 0
k=0: a0 = 241 mod 2 = 1, q = 241 div 2 = 120 6= 0
k=1:a1 = 0, q = 60
k=2:a2 = 0, q = 30
k=3:a3 = 0, q = 15
k=4:a4 = 1, q = 7
k=5:a5 = 1, q = 3
k=6:a6 = 1, 1 = 1
k=7:a7 = 1, q = 0
Solution.
q = 241 6= 0
k=0: a0 = 241 mod 2 = 1, q = 241 div 2 = 120 6= 0
k=1:a1 = 0, q = 60
k=2:a2 = 0, q = 30
k=3:a3 = 0, q = 15
k=4:a4 = 1, q = 7
k=5:a5 = 1, q = 3
k=6:a6 = 1, 1 = 1
k=7:a7 = 1, q = 0
→ 11110001,so 241 = (11110001)2
Quizz
Quizz
Ans: a
Quizz
Quizz
Ans:b
1 = 0.2 + 1
1 = 0.2 + 1
2 = 1.2 + 0
1 = 0.2 + 1
2 = 1.2 + 0
2 = 1.2 + 0
1 = 0.2 + 1
2 = 1.2 + 0
2 = 1.2 + 0
3 = 1.2 + 1
1 = 0.2 + 1
2 = 1.2 + 0
2 = 1.2 + 0
3 = 1.2 + 1
1 = 0.2 + 1
1 = 0.2 + 1
2 = 1.2 + 0
2 = 1.2 + 0
3 = 1.2 + 1
1 = 0.2 + 1
1 = 0.2 + 1
2 = 1.2 + 0
2 = 1.2 + 0
3 = 1.2 + 1
1 = 0.2 + 1
Thus, (1110)2 + (1011)2 = (11001)2
Lai Văn Phút Chapter 4. Number Theory and Cryptography
The Integers and Division Integers and Algorithms Primes and Greatest Common Divisors Problems
Rules.
• 0−0 = 0
Rules.
• 0−0 = 0
• 1−0 = 1
Rules.
• 0−0 = 0
• 1−0 = 1
• 1−1 = 0
Rules.
• 0−0 = 0
• 1−0 = 1
• 1−1 = 0
• 0 − 1 = 1( remind − 1)
Rules.
• 0−0 = 0
• 1−0 = 1
• 1−1 = 0
• 0 − 1 = 1( remind − 1)
• −1 − 1 = 0( remind − 1)
Rules.
• 0−0 = 0
• 1−0 = 1
• 1−1 = 0
• 0 − 1 = 1( remind − 1)
• −1 − 1 = 0( remind − 1)
Rules.
• 0−0 = 0
• 1−0 = 1
• 1−1 = 0
• 0 − 1 = 1( remind − 1)
• −1 − 1 = 0( remind − 1)
Let a = (1110)2 and b = (1011)2 . Find a − b
Rules.
• 0−0 = 0
• 1−0 = 1
• 1−1 = 0
• 0 − 1 = 1( remind − 1)
• −1 − 1 = 0( remind − 1)
Let a = (1110)2 and b = (1011)2 . Find a − b
(1110)2 − (1011)2 = (11)2
Addition Algorithm
Addition Algorithm
Solution
c=0
j = 0 :d = b 0+12+0 c = b0.5c = 0
s0 = 1, c = 0
Solution
c=0
j = 0 :d = b 0+12+0 c = b0.5c = 0
s0 = 1, c = 0
j = 1 :d = b 1+12+0 c = b1c = 1
s1 = 0, c = 1
Solution
c=0
j = 0 :d = b 0+12+0 c = b0.5c = 0
s0 = 1, c = 0
j = 1 :d = b 1+12+0 c = b1c = 1
s1 = 0, c = 1
j = 2 :d = 1
s2 = 0, c = 1
Solution
c=0
j = 0 :d = b 0+12+0 c = b0.5c = 0
s0 = 1, c = 0
j = 1 :d = b 1+12+0 c = b1c = 1
s1 = 0, c = 1
j = 2 :d = 1
s2 = 0, c = 1
j = 3 :d = 1
s3 = 1, c = 1
Solution
c=0
j = 0 :d = b 0+12+0 c = b0.5c = 0
s0 = 1, c = 0
j = 1 :d = b 1+12+0 c = b1c = 1
s1 = 0, c = 1
j = 2 :d = 1
s2 = 0, c = 1
j = 3 :d = 1
s3 = 1, c = 1
s4 = 1
Solution
c=0
j = 0 :d = b 0+12+0 c = b0.5c = 0
s0 = 1, c = 0
j = 1 :d = b 1+12+0 c = b1c = 1
s1 = 0, c = 1
j = 2 :d = 1
s2 = 0, c = 1
j = 3 :d = 1
s3 = 1, c = 1
s4 = 1
Solution
c=0
j = 0 :d = b 0+12+0 c = b0.5c = 0
s0 = 1, c = 0
j = 1 :d = b 1+12+0 c = b1c = 1
s1 = 0, c = 1
j = 2 :d = 1
s2 = 0, c = 1
j = 3 :d = 1
s3 = 1, c = 1
s4 = 1
→ 10011, so the sum is (11001)2
Multiplication Algorithm
Multiplication Algorithm
Solution.
j = 0 : b0 = 1 → c0 =
110
Solution.
j = 0 : b0 = 1 → c0 =
110
j = 1 : b1 = 0 → c1 =
0000
Solution.
j = 0 : b0 = 1 → c0 =
110
j = 1 : b1 = 0 → c1 =
0000
j = 2 : b2 = 1 → c2 =
11000
Solution.
j = 0 : b0 = 1 → c0 =
110
j = 1 : b1 = 0 → c1 =
0000
j = 2 : b2 = 1 → c2 =
11000
Solution.
p=0
j = 0 : b0 = 1 → c0 =
110 j = 0 : p = 0 + 110 =
110
j = 1 : b1 = 0 → c1 =
0000
j = 2 : b2 = 1 → c2 =
11000
Solution.
p=0
j = 0 : b0 = 1 → c0 =
110 j = 0 : p = 0 + 110 =
110
j = 1 : b1 = 0 → c1 =
0000 j=1:p=
110 + 0000 = 0110
j = 2 : b2 = 1 → c2 =
11000
Solution.
p=0
j = 0 : b0 = 1 → c0 =
110 j = 0 : p = 0 + 110 =
110
j = 1 : b1 = 0 → c1 =
0000 j=1:p=
110 + 0000 = 0110
j = 2 : b2 = 1 → c2 =
11000 j=2:p=
0110 + 11000 = 11110
Solution.
p=0
j = 0 : b0 = 1 → c0 =
110 j = 0 : p = 0 + 110 =
110
j = 1 : b1 = 0 → c1 =
0000 j=1:p=
110 + 0000 = 0110
j = 2 : b2 = 1 → c2 =
11000 j=2:p=
0110 + 11000 = 11110
Solution.
p=0 →
j = 0 : b0 = 1 → c0 =
110 j = 0 : p = 0 + 110 =
110
j = 1 : b1 = 0 → c1 =
0000 j=1:p=
110 + 0000 = 0110
j = 2 : b2 = 1 → c2 =
11000 j=2:p=
0110 + 11000 = 11110
p = 11110. Hence, the product (11110)2
Division Algorithm
Division Algorithm
Solution.
q = 0, r = |101| = 101
r = 101 ≥ 11 = d →
r = 101 − 11 = 90, q =
0+1 = 1
Solution.
q = 0, r = |101| = 101
r = 101 ≥ 11 = d →
r = 101 − 11 = 90, q =
0+1 = 1
r = 90 ≥ 11 = d →
r = 79, q = 2
Solution.
q = 0, r = |101| = 101
r = 101 ≥ 11 = d →
r = 101 − 11 = 90, q =
0+1 = 1
r = 90 ≥ 11 = d →
r = 79, q = 2
r = 79 ≥ 11 = d →
r = 61, q = 3
Solution.
q = 0, r = |101| = 101
r = 101 ≥ 11 = d →
r = 101 − 11 = 90, q =
0+1 = 1
r = 90 ≥ 11 = d →
r = 79, q = 2
r = 79 ≥ 11 = d →
r = 61, q = 3
r = 61 ≥ 11 = d →
r = 57, q = 4
Solution.
q = 0, r = |101| = 101
r = 101 ≥ 11 = d →
r = 101 − 11 = 90, q =
0+1 = 1
r = 90 ≥ 11 = d →
r = 79, q = 2
r = 79 ≥ 11 = d →
r = 61, q = 3
r = 61 ≥ 11 = d →
r = 57, q = 4
r = 57 ≥ 11 = d →
r = 46, q = 5
Solution.
q = 0, r = |101| = 101
r = 101 ≥ 11 = d →
r = 101 − 11 = 90, q =
0+1 = 1
r = 90 ≥ 11 = d →
r = 79, q = 2
r = 79 ≥ 11 = d →
r = 61, q = 3
r = 61 ≥ 11 = d →
r = 57, q = 4
r = 57 ≥ 11 = d →
r = 46, q = 5
Solution.
q = 0, r = |101| = 101
r = 101 ≥ 11 = d → r = 46 ≥ 11 = d →
r = 101 − 11 = 90, q = r = 35, q = 6
0+1 = 1
r = 90 ≥ 11 = d →
r = 79, q = 2
r = 79 ≥ 11 = d →
r = 61, q = 3
r = 61 ≥ 11 = d →
r = 57, q = 4
r = 57 ≥ 11 = d →
r = 46, q = 5
Solution.
q = 0, r = |101| = 101
r = 101 ≥ 11 = d → r = 46 ≥ 11 = d →
r = 101 − 11 = 90, q = r = 35, q = 6
0+1 = 1 r = 35 ≥ 11 = d →
r = 90 ≥ 11 = d → r = 24, q = 7
r = 79, q = 2
r = 79 ≥ 11 = d →
r = 61, q = 3
r = 61 ≥ 11 = d →
r = 57, q = 4
r = 57 ≥ 11 = d →
r = 46, q = 5
Solution.
q = 0, r = |101| = 101
r = 101 ≥ 11 = d → r = 46 ≥ 11 = d →
r = 101 − 11 = 90, q = r = 35, q = 6
0+1 = 1 r = 35 ≥ 11 = d →
r = 90 ≥ 11 = d → r = 24, q = 7
r = 79, q = 2 r = 24 ≥ 11 = d →
r = 79 ≥ 11 = d → r = 13, q = 8
r = 61, q = 3
r = 61 ≥ 11 = d →
r = 57, q = 4
r = 57 ≥ 11 = d →
r = 46, q = 5
Solution.
q = 0, r = |101| = 101
r = 101 ≥ 11 = d → r = 46 ≥ 11 = d →
r = 101 − 11 = 90, q = r = 35, q = 6
0+1 = 1 r = 35 ≥ 11 = d →
r = 90 ≥ 11 = d → r = 24, q = 7
r = 79, q = 2 r = 24 ≥ 11 = d →
r = 79 ≥ 11 = d → r = 13, q = 8
r = 61, q = 3 r = 13 ≥ 11 = d →
r = 61 ≥ 11 = d → r = 2, q = 9
r = 57, q = 4
r = 57 ≥ 11 = d →
r = 46, q = 5
Solution.
q = 0, r = |101| = 101
r = 101 ≥ 11 = d → r = 46 ≥ 11 = d →
r = 101 − 11 = 90, q = r = 35, q = 6
0+1 = 1 r = 35 ≥ 11 = d →
r = 90 ≥ 11 = d → r = 24, q = 7
r = 79, q = 2 r = 24 ≥ 11 = d →
r = 79 ≥ 11 = d → r = 13, q = 8
r = 61, q = 3 r = 13 ≥ 11 = d →
r = 61 ≥ 11 = d → r = 2, q = 9
r = 57, q = 4 r = 2 ≥ 11 = d(!)
r = 57 ≥ 11 = d →
r = 46, q = 5
Solution.
q = 0, r = |101| = 101
r = 101 ≥ 11 = d → r = 46 ≥ 11 = d →
r = 101 − 11 = 90, q = r = 35, q = 6
0+1 = 1 r = 35 ≥ 11 = d →
r = 90 ≥ 11 = d → r = 24, q = 7
r = 79, q = 2 r = 24 ≥ 11 = d →
r = 79 ≥ 11 = d → r = 13, q = 8
r = 61, q = 3 r = 13 ≥ 11 = d →
r = 61 ≥ 11 = d → r = 2, q = 9
r = 57, q = 4 r = 2 ≥ 11 = d(!)
r = 57 ≥ 11 = d →
r = 46, q = 5
Solution.
q = 0, r = |101| = 101
r = 101 ≥ 11 = d → r = 46 ≥ 11 = d →
r = 101 − 11 = 90, q = r = 35, q = 6
0+1 = 1 r = 35 ≥ 11 = d →
r = 90 ≥ 11 = d → r = 24, q = 7
r = 79, q = 2 r = 24 ≥ 11 = d →
r = 79 ≥ 11 = d → r = 13, q = 8
r = 61, q = 3 r = 13 ≥ 11 = d →
r = 61 ≥ 11 = d → r = 2, q = 9
r = 57, q = 4 r = 2 ≥ 11 = d(!)
r = 57 ≥ 11 = d → Hence, (q = 9, r = 2)
r = 46, q = 5
Modular Exponentiation
Modular Exponentiation
Solution.
We have b = 3, m = 645, 644 = (1010000100)2
Solution.
We have b = 3, m = 645, 644 = (1010000100)2
x =1
power = 3 mod 645 = 3
i = 0 : a0 = 0 → x = 1, power = 32 mod 645 = 9
Solution.
We have b = 3, m = 645, 644 = (1010000100)2
x =1
power = 3 mod 645 = 3
i = 0 : a0 = 0 → x = 1, power = 32 mod 645 = 9
i = 1 : a1 = 0 → x = 1, power = 92 mod 645 = 81
Solution.
We have b = 3, m = 645, 644 = (1010000100)2
x =1
power = 3 mod 645 = 3
i = 0 : a0 = 0 → x = 1, power = 32 mod 645 = 9
i = 1 : a1 = 0 → x = 1, power = 92 mod 645 = 81
i = 2 : a2 = 1 → x = 1.81 mod 645 = 81, power =
812 mod 645 = 111
Solution.
We have b = 3, m = 645, 644 = (1010000100)2
x =1
power = 3 mod 645 = 3
i = 0 : a0 = 0 → x = 1, power = 32 mod 645 = 9
i = 1 : a1 = 0 → x = 1, power = 92 mod 645 = 81
i = 2 : a2 = 1 → x = 1.81 mod 645 = 81, power =
812 mod 645 = 111
i = 3 : a3 = 0 → x = 81, power = 1112 mod 645 = 66
Solution.
We have b = 3, m = 645, 644 = (1010000100)2
x =1
power = 3 mod 645 = 3
i = 0 : a0 = 0 → x = 1, power = 32 mod 645 = 9
i = 1 : a1 = 0 → x = 1, power = 92 mod 645 = 81
i = 2 : a2 = 1 → x = 1.81 mod 645 = 81, power =
812 mod 645 = 111
i = 3 : a3 = 0 → x = 81, power = 1112 mod 645 = 66
i = 4 : a4 = 0 → x = 81, power = 662 mod 645 = 486
Solution.
We have b = 3, m = 645, 644 = (1010000100)2
x =1
power = 3 mod 645 = 3
i = 0 : a0 = 0 → x = 1, power = 32 mod 645 = 9
i = 1 : a1 = 0 → x = 1, power = 92 mod 645 = 81
i = 2 : a2 = 1 → x = 1.81 mod 645 = 81, power =
812 mod 645 = 111
i = 3 : a3 = 0 → x = 81, power = 1112 mod 645 = 66
i = 4 : a4 = 0 → x = 81, power = 662 mod 645 = 486
i = 5 : a5 = 0 → x = 81, power = 4862 mod 645 = 126
Solution.
We have b = 3, m = 645, 644 = (1010000100)2
x =1
power = 3 mod 645 = 3
i = 0 : a0 = 0 → x = 1, power = 32 mod 645 = 9
i = 1 : a1 = 0 → x = 1, power = 92 mod 645 = 81
i = 2 : a2 = 1 → x = 1.81 mod 645 = 81, power =
812 mod 645 = 111
i = 3 : a3 = 0 → x = 81, power = 1112 mod 645 = 66
i = 4 : a4 = 0 → x = 81, power = 662 mod 645 = 486
i = 5 : a5 = 0 → x = 81, power = 4862 mod 645 = 126
i = 6 : a6 = 0 → x = 81, power = 1262 mod 645 = 396
Solution.
We have b = 3, m = 645, 644 = (1010000100)2
x =1
power = 3 mod 645 = 3
i = 0 : a0 = 0 → x = 1, power = 32 mod 645 = 9
i = 1 : a1 = 0 → x = 1, power = 92 mod 645 = 81
i = 2 : a2 = 1 → x = 1.81 mod 645 = 81, power =
812 mod 645 = 111
i = 3 : a3 = 0 → x = 81, power = 1112 mod 645 = 66
i = 4 : a4 = 0 → x = 81, power = 662 mod 645 = 486
i = 5 : a5 = 0 → x = 81, power = 4862 mod 645 = 126
i = 6 : a6 = 0 → x = 81, power = 1262 mod 645 = 396
i = 7 : a7 = 1 → x = (81.396) mod 645 = 471, power =
3962 mod 645 = 81
Solution.
We have b = 3, m = 645, 644 = (1010000100)2
x =1
power = 3 mod 645 = 3
i = 0 : a0 = 0 → x = 1, power = 32 mod 645 = 9
i = 1 : a1 = 0 → x = 1, power = 92 mod 645 = 81
i = 2 : a2 = 1 → x = 1.81 mod 645 = 81, power =
812 mod 645 = 111
i = 3 : a3 = 0 → x = 81, power = 1112 mod 645 = 66
i = 4 : a4 = 0 → x = 81, power = 662 mod 645 = 486
i = 5 : a5 = 0 → x = 81, power = 4862 mod 645 = 126
i = 6 : a6 = 0 → x = 81, power = 1262 mod 645 = 396
i = 7 : a7 = 1 → x = (81.396) mod 645 = 471, power =
3962 mod 645 = 81
i = 8 : a8 = 0 → x = 471, power = 812 mod 645 = 111
Lai Văn Phút Chapter 4. Number Theory and Cryptography
The Integers and Division Integers and Algorithms Primes and Greatest Common Divisors Problems
Solution.
Solution.
Solution.
Primes
Definition.
• A positive integer p greater than 1 is called prime (số
nguyên tố) if the only positive factors (ước số) are 1
and p.
Primes
Definition.
• A positive integer p greater than 1 is called prime (số
nguyên tố) if the only positive factors (ước số) are 1
and p.
• A positive integer that is greater than 1 and is not
prime is called composite (hợp số).
Example.
Theorem
Theorem
Theorem
Theorem
Solutions.
Solutions.
Theorem
Theorem
Examples.
1. gcd (24, 36)
Examples.
1. gcd (24, 36)
Examples.
1. gcd (24, 36)→ gcd (24, 36) = 12
2. gcd (17, 22)
Lai Văn Phút Chapter 4. Number Theory and Cryptography
The Integers and Division Integers and Algorithms Primes and Greatest Common Divisors Problems
Examples.
1. gcd (24, 36)→ gcd (24, 36) = 12
2. gcd (17, 22)
Lai Văn Phút Chapter 4. Number Theory and Cryptography
The Integers and Division Integers and Algorithms Primes and Greatest Common Divisors Problems
Examples.
1. gcd (24, 36)→ gcd (24, 36) = 12
2. gcd (17, 22)→ gcd (17, 22) = 1
Lai Văn Phút Chapter 4. Number Theory and Cryptography
The Integers and Division Integers and Algorithms Primes and Greatest Common Divisors Problems
Definition.
Definition.
Definition.
Definition.
Definition.
Examples.
1. lcm(12, 36)
Examples.
1. lcm(12, 36)
Examples.
1. lcm(12, 36)→ lcm(12, 36) = 36
2. lcm(7, 17)
Lai Văn Phút Chapter 4. Number Theory and Cryptography
The Integers and Division Integers and Algorithms Primes and Greatest Common Divisors Problems
Examples.
1. lcm(12, 36)→ lcm(12, 36) = 36
2. lcm(7, 17)
Lai Văn Phút Chapter 4. Number Theory and Cryptography
The Integers and Division Integers and Algorithms Primes and Greatest Common Divisors Problems
Examples.
1. lcm(12, 36)→ lcm(12, 36) = 36
2. lcm(7, 17)→ lcm(7, 17) = 119
Lai Văn Phút Chapter 4. Number Theory and Cryptography
The Integers and Division Integers and Algorithms Primes and Greatest Common Divisors Problems
Theorem
Theorem
Solution.
x = 24
y = 36
y = 36 6= 0 : r = 24 mod 36 = 24, x = 36, y = 24
Solution.
x = 24
y = 36
y = 36 6= 0 : r = 24 mod 36 = 24, x = 36, y = 24
y = 24 6= 0 : r = 36 mod 24 = 12, x = 24, y = 12
Solution.
x = 24
y = 36
y = 36 6= 0 : r = 24 mod 36 = 24, x = 36, y = 24
y = 24 6= 0 : r = 36 mod 24 = 12, x = 24, y = 12
y = 12 6= 0 : r = 24 mod 12 = 0, x = 12, y = 0
Solution.
x = 24
y = 36
y = 36 6= 0 : r = 24 mod 36 = 24, x = 36, y = 24
y = 24 6= 0 : r = 36 mod 24 = 12, x = 24, y = 12
y = 12 6= 0 : r = 24 mod 12 = 0, x = 12, y = 0
y = 0 6 = 0( ! )
Solution.
x = 24
y = 36
y = 36 6= 0 : r = 24 mod 36 = 24, x = 36, y = 24
y = 24 6= 0 : r = 36 mod 24 = 12, x = 24, y = 12
y = 12 6= 0 : r = 24 mod 12 = 0, x = 12, y = 0
y = 0 6 = 0( ! )
Solution.
x = 24
y = 36
y = 36 6= 0 : r = 24 mod 36 = 24, x = 36, y = 24
y = 24 6= 0 : r = 36 mod 24 = 12, x = 24, y = 12
y = 12 6= 0 : r = 24 mod 12 = 0, x = 12, y = 0
y = 0 6 = 0( ! )
→ return 12. Hence, gcd (24, 36) = 12
Euler ϕ-function
Euler ϕ-function
Quizz
Quizz
Ans: b
Quizz
Quizz
Ans: a