0% found this document useful (0 votes)
38 views35 pages

3-Module - 1 Fundamentals of Number Theory-04-01-2024

This document discusses several key topics in number theory including prime numbers, prime factorization, modular arithmetic, the Euclidean algorithm for finding the greatest common divisor, Fermat's theorem, and Miller-Rabin primality testing. It provides examples and explanations of these fundamental number theory concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views35 pages

3-Module - 1 Fundamentals of Number Theory-04-01-2024

This document discusses several key topics in number theory including prime numbers, prime factorization, modular arithmetic, the Euclidean algorithm for finding the greatest common divisor, Fermat's theorem, and Miller-Rabin primality testing. It provides examples and explanations of these fundamental number theory concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Cryptography and

Network Security
Chapter 8
Fifth Edition
by William Stallings

Lecture slides by Lawrie Brown


Modified by Richard Newman
Chapter 8 – Introduction to
Number Theory
The Devil said to Daniel Webster: "Set me a task I can't carry out, and
I'll give you anything in the world you ask for."
Daniel Webster: "Fair enough. Prove that for n greater than 2, the
equation an + bn = cn has no non-trivial solution in the integers."
They agreed on a three-day period for the labor, and the Devil
disappeared.
At the end of three days, the Devil presented himself, haggard, jumpy,
biting his lip. Daniel Webster said to him, "Well, how did you do at
my task? Did you prove the theorem?'
"Eh? No . . . no, I haven't proved it."
"Then I can have whatever I ask for? Money? The Presidency?'
"What? Oh, that—of course. But listen! If we could just prove the
following two lemmas—"
—The Mathematical Magpie, Clifton Fadiman
Prime Numbers
 prime numbers only have divisors of 1 and self
 they cannot be written as a product of other numbers
 note: 1 is prime, but is generally not of interest
 eg. 2,3,5,7 are prime, 4,6,8,9,10 are not
 prime numbers are central to number theory
 list of prime number less than 200 is:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59
61 67 71 73 79 83 89 97 101 103 107 109 113 127
131 137 139 149 151 157 163 167 173 179 181 191
193 197 199
Prime Factorization
 tofactor a number n is to write it as a
product of other numbers: n=a x b x c
 note that factoring a number is relatively
hard compared to multiplying the factors
together to generate the number
 Fundamental theorem of arithmetic
 the prime factorization of a number n is
when its written as a product of primes
 eg. 91=7x13 ; 3600=24x32x52
Relatively Prime Numbers &
GCD
 two numbers a, b are relatively prime if have
no common divisors apart from 1
 eg. 8 & 15 are relatively prime since factors of 8 are
1,2,4,8 and of 15 are 1,3,5,15 and 1 is the only
common factor
 conversely can determine the greatest common
divisor by comparing their prime factorizations
and using least powers
 eg. 300=21x31x52 18=21x32 hence
GCD(18,300)=21x31x50=6
Greatest Common Divisor (GCD)

a common problem in number theory


 GCD (a,b) of a and b is the largest integer
that divides evenly into both a and b
 eg GCD(60,24) = 12
 define gcd(0, 0) = 0
 often want no common factors (except 1)
define such numbers as relatively prime
 eg GCD(8,15) = 1
 hence 8 & 15 are relatively prime
Example GCD(1970,1066)
1970 = 1 x 1066 + 904 gcd(1066, 904)
1066 = 1 x 904 + 162 gcd(904, 162)
904 = 5 x 162 + 94 gcd(162, 94)
162 = 1 x 94 + 68 gcd(94, 68)
94 = 1 x 68 + 26 gcd(68, 26)
68 = 2 x 26 + 16 gcd(26, 16)
26 = 1 x 16 + 10 gcd(16, 10)
16 = 1 x 10 + 6 gcd(10, 6)
10 = 1 x 6 + 4 gcd(6, 4)
6 = 1 x 4 + 2 gcd(4, 2)
4 = 2 x 2 + 0 gcd(2, 0)
GCD(1160718174, 316258250)
Dividend Divisor Quotient Remainder
a = 1160718174 b = 316258250 q1 = 3 r1 = 211943424
b = 316258250 r1 = 211943424 q2 = 1 r2 = 104314826
r1 = 211943424 r2 = 104314826 q3 = 2 r3 = 3313772
r2 = 104314826 r3 = 3313772 q4 = 31 r4 = 1587894
r3 = 3313772 r4 = 1587894 q5 = 2 r5 = 137984
r4 = 1587894 r5 = 137984 q6 = 11 r6 = 70070
r5 = 137984 r6 = 70070 q7 = 1 r7 = 67914
r6 = 70070 r7 = 67914 q8 = 1 r8 = 2516
r7 = 67914 r8 = 2516 q9 = 31 r9 = 1078
r8 = 2516 r9 = 1078 q10 = 2 r10 = 0
Modular Arithmetic
 define modulo operator “a mod n” to be
remainder when a is divided by n
 where integer n is called the modulus
 b is called a residue of a mod n
 since with integers can always write: a = qn + b
 usually chose smallest positive remainder as residue
• ie. 0 <= b <= n-1
 process is known as modulo reduction
• eg. -12 mod 7 = -5 mod 7 = 2 mod 7 = 9 mod 7
 a & b are congruent if: a mod n = b mod n
 when divided by n, a & b have same remainder
 eg. 100 = 34 mod 11
Modular Arithmetic Operations
 can perform arithmetic with residues
 uses a finite number of values, and loops
back from either end
Zn = {0, 1, . . . , (n – 1)}
 modular arithmetic is when do addition &
multiplication and modulo reduce answer
 can do reduction at any point, ie
 a+b mod n = [a mod n + b mod n] mod n
Modular Arithmetic Operations
1. [(a mod n) + (b mod n)] mod n
= (a + b) mod n
2. [(a mod n) – (b mod n)] mod n
= (a – b) mod n
3. [(a mod n) x (b mod n)] mod n
= (a x b) mod n
e.g.
[(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) x (15 mod 8)] mod 8 = 21 mod 8 = 5 (11 x 15) mod 8 = 165 mod 8 = 5
Modulo 8 Addition Example
+ 0 1 2 3 4 5 6 7
0 0 1 2 3 4 5 6 7
1 1 2 3 4 5 6 7 0
2 2 3 4 5 6 7 0 1
3 3 4 5 6 7 0 1 2
4 4 5 6 7 0 1 2 3
5 5 6 7 0 1 2 3 4
6 6 7 0 1 2 3 4 5
7 7 0 1 2 3 4 5 6
Modulo 8 Multiplication
+ 0 1 2 3 4 5 6 7
0 0 0 0 0 0 0 0 0
1 0 1 2 3 4 5 6 7
2 0 2 4 6 0 2 4 6
3 0 3 6 1 4 7 2 5
4 0 4 0 4 0 4 0 4
5 0 5 2 7 4 1 6 3
6 0 6 4 2 0 6 4 2
7 0 7 6 5 4 3 2 1
Modular Arithmetic Properties
Euclidean Algorithm
 an efficient way to find the GCD(a,b)
 uses theorem that:
 GCD(a,b) = GCD(b, a mod b)
 Euclidean Algorithm to compute GCD(a,b) is:
Euclid(a,b)
if (b=0) then return a;
else return Euclid(b, a mod b);
Basic Euclidean Algorithm
Euclidean Algorithm
Euclidean Algorithm- Ex
 The Euclidean Algorithm finds the gcd(a,b):
 Example: gcd(1180, 482)

1180 = 2 · 482 + 216

482 = 2 · 216 + 50

216 = 4 · 50 + 16

50 = 3 · 16 + 2

16 = 8 · 2 + 0.

 Last non-zero remainder is the gcd.


Extended Euclidean Algorithm
 calculates not only GCD but x & y:
ax + by = d = gcd(a, b)
 useful for later crypto computations
 follow sequence of divisions for GCD but
assume at each step i, can find x &y:
r = ax + by
 at end find GCD value and also x & y
 if GCD(a,b)=1 these values are inverses
Finding Inverses
EXTENDED EUCLID(m, b)
1. (A1, A2, A3)=(1, 0, m);
(B1, B2, B3)=(0, 1, b)
2. if B3 = 0
return A3 = gcd(m, b); no inverse
3. if B3 = 1
return B3 = gcd(m, b); B2 = b–1 mod m
4. Q = A3 div B3
5. (T1, T2, T3)=(A1 – Q B1, A2 – Q B2, A3 – Q B3)
6. (A1, A2, A3)=(B1, B2, B3)
7. (B1, B2, B3)=(T1, T2, T3)
8. goto 2
Fermat's Theorem
 ap-1 = 1 (mod p)
 where p is prime and gcd(a,p)=1
 also known as Fermat’s Little Theorem
 also have: ap = a (mod p)
 useful in public key and primality testing
Euler Totient Function ø(n)
 when doing arithmetic modulo n
 complete set of residues is: 0..n-1
 reduced set of residues is those numbers
(residues) which are relatively prime to n
 eg for n=10,
 complete set of residues is {0,1,2,3,4,5,6,7,8,9}
 reduced set of residues is {1,3,7,9}
 number of elements in reduced set of residues is
called the Euler Totient Function ø(n)
Euler Totient Function ø(n)
 to compute ø(n) need to count number of
residues to be excluded
 in general need prime factorization, but
 for p (p prime) ø(p)=p-1
 for p.q (p,q prime) ø(p.q)=(p-1)x(q-1)
 eg.
ø(37) = 36
ø(21) = (3–1)x(7–1) = 2x6 = 12
Euler's Theorem
 a generalisation of Fermat's Theorem
 aø(n) = 1 (mod n)
 for any a,n where gcd(a,n)=1
 eg.
a=3;n=10; ø(10)=4;
hence 34 = 81 = 1 mod 10
a=2;n=11; ø(11)=10;
hence 210 = 1024 = 1 mod 11
 also have: aø(n)+1 = a (mod n)
Primality Testing
 often need to find large prime numbers
 traditionally sieve using trial division
 ie. divide by all numbers (primes) in turn less than the
square root of the number
 only works for small numbers
 alternatively can use statistical primality tests
based on properties of primes
 for which all primes numbers satisfy property
 but some composite numbers, called pseudo-primes,
also satisfy the property
 can use a slower deterministic primality test
Miller Rabin Algorithm
 a test based on prime properties that result from
Fermat’s Theorem
 algorithm is:
TEST (n) is:
1. Find integers k, q, k > 0, q odd, so that (n–1)=2kq
2. Select a random integer a, 1<a<n–1
3. if aq mod n = 1 then return (“inconclusive");
4. for j = 0 to k – 1 do
j
5. if (a2 q mod n = n-1)
then return(“inconclusive")
6. return (“composite")
Probabilistic Considerations
 ifMiller-Rabin returns “composite” the
number is definitely not prime
 otherwise is a prime or a pseudo-prime
 chance it detects a pseudo-prime is < 1/4
 hence if repeat test with different random a
then chance n is prime after t tests is:
 Pr(n prime after t tests) = 1-4-t
 eg. for t=10 this probability is > 0.99999
 could then use the deterministic AKS test
Prime Distribution
 primenumber theorem states that primes
occur roughly every (ln n) integers
 but can immediately ignore evens
 so in practice need only test 0.5 ln(n)
numbers of size n to locate a prime
 note this is only the “average”
 sometimes primes are close together
 other times are quite far apart
Chinese Remainder Theorem
 used to speed up modulo computations
 if working modulo a product of numbers
 e.g., mod M, where M = m1m2..mk
 Chinese Remainder theorem lets us work
in each modulus mi separately
 since computational cost is proportional to
size, this is faster than working in the full
modulus M
Chinese Remainder Theorem
 can implement CRT in several ways
 to compute A(mod M)
 first compute all ai = A mod mi separately
 determine constants ci below, where Mi = M/mi
 then combine results to get answer using:
Primitive Roots
 from Euler’s theorem have aø(n)mod n=1
 consider am=1 (mod n), GCD(a,n)=1
 must exist for m = ø(n) but may be smaller
 once powers reach m, cycle will repeat
 if smallest is m = ø(n) then a is called a
primitive root
 if p is prime, then successive powers of a
"generate" the group mod p
 these are useful but relatively hard to find
Powers mod 19
Discrete Logarithms
 the inverse problem to exponentiation is to find
the discrete logarithm of a number modulo p
 that is to find i such that b = ai (mod p)
 this is written as i = dloga b (mod p)
 if a is a primitive root then it always exists,
otherwise it may not, e.g.,
x = log3 4 mod 13 has no answer
x = log2 3 mod 13 = 4 by trying successive powers
 whilst exponentiation is relatively easy, finding
discrete logarithms is generally a hard problem
Discrete Logarithms mod 19
Summary
 have considered:
 prime numbers
 Fermat’s and Euler’s Theorems & ø(n)
 Primality Testing
 Chinese Remainder Theorem
 Primitive Roots & Discrete Logarithms

You might also like