Lecture 9: Basic Number Theory

Download Report

Transcript Lecture 9: Basic Number Theory

Basic Number Theory
2017/4/12
Kazi A Kalpoma
1
Z = {…… -4,-3,-2,-1, 0, 1, 2, 3, 4,…..}
• Number Theory is the mathematics of the integers.
• It is a subset of the integers
• the primes those positive integers with no proper positive factors
other than 1, that are particularly important in computer science.
• An important result of number theory shows that the primes are
the multiplicative building blocks of the positive integers.
• This result, called the fundamental theorem of arithmetic,
says that every positive integer can be uniquely written as a
product of primes.
2017/4/12
Kazi A Kalpoma
2
Agenda
• Divisors
• Primes or Primality
• Fundamental Theorem of Arithmetic
• Division Algorithm
• Greatest common divisors/least common
multiples
• Relative Primality
• Modular arithmetic
• Caesar’s Cipher
2017/4/12
Kazi A Kalpoma
3
Number theory
• Given two integers, say a and b, the quotient b/a
may or may not be an integer (e.g., 16/4 = 4 but
12/5 = 2.4).
• Number theory concerns the former case, and
discovers criteria upon which one can decide about
divisibility of two integers.
• More formally, for a≠0 we say that b is divisible by a
if there is another integer k such that
b = k.a,
and we can write a divides b i.e. a|b
In short:
a|b if and only if k∊Z b = k.a.
• This simple definition leads to many properties of divisibility.
2017/4/12
Kazi A Kalpoma
4
Divisors
DEF: Let a, b and c be integers such that
b = a·c
Then a and c are said to divide (or are factors) of b,
while b is said to be a multiple of a (as well as of
c). The pipe symbol “|” denotes “divides” so the
situation is summarized by:
a|b c|b.
NOTE: you may find notation “|” and “/” confusing,
and think of “|” in the reverse fashion, perhaps
confuse pipe with forward slash “/”
2017/4/12
Kazi A Kalpoma
5
Divisors (Examples)
Q: Which of the following is true?
1. 77 | 7
2. 7 | 77
3. 24 | 24
4. 0 | 24
5. 24 | 0
2017/4/12
Kazi A Kalpoma
6
Divisors (Examples)
Answer :
1.
77 | 7: false because bigger number can’t divide
smaller positive number
2. 7 | 77: true because 77 = 7 · 11
3.
24 | 24: true because 24 = 24 · 1
4.
0 | 24: false, only 0 is divisible by 0
5.
24 | 0: true, 0 is divisible by every number (0 = 24
· 0)
2017/4/12
Kazi A Kalpoma
7
Formula for Number of Multiples up to given n
Q: How many positive multiples of 15 are less
than 100?
A: Just list them:
15, 30, 45, 60, 75, 90
Therefore the answer is 6.
The answer is equal to 100/15.
2017/4/12
Kazi A Kalpoma
8
Formula for Number of Multiples up to Given n
In general: The number of d-multiples
less than N is given by:
|{m  Z+ | d |m and m  N }| = N/d
2017/4/12
Kazi A Kalpoma
9
Divisor Theorem
THM: Let a, b, and c be integers. Then:
1. a|b  a|c  a|(b + c )
2. a|b  a|bc for all integers c
3. a|b  b|c  a|c
EG:
1. 7|21  7|35  7|(21+35) [ 7|56 ]
2. 7|21  7|210 [ here c=10]
3. 7|14  14|42  7|42
2017/4/12
Kazi A Kalpoma
10
EG. Proof of no. 1 a|b  a|c  a|(b + c )
• From the definition of divisibility and
the hypotheses we know that there are
integers t and s such that
b = ta; c = sa:
Hence
b + c = = ta+sa =a(s + t)
Since s + t is an integer, we prove that
a|(b + c).
2017/4/12
Kazi A Kalpoma
11
Proof of no. 2
In general, such statements are proved by starting from
the definitions and manipulating to get the desired
results.
EG. Proof of no. 2 (a|b  a|bc ): for all integer c
Suppose a|b. By definition, there is a number k such that
b= ak.
Multiply both sides by c to get bc = akc = a (kc).
Consequently, bc = a (kc)
so by definition of “|”, a|bc
2017/4/12
Kazi A Kalpoma
12
Theme 2: Primes
• Primes numbers occupy very prominent role in
number theory.
• A prime number p is an integer greater than 1 that
is divisible only by 1 and itself.
• A number that is not prime is called composite.
• Example 1:
The primes less than 100 are:
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:
2017/4/12
Kazi A Kalpoma
13
Prime Numbers
DEF: A number n  2 is prime if it is
only divisible by 1 and itself. A number
n  2 which isn’t prime is called
composite.
Q: Which of the following are prime?
0,1,2,3,4,5,6,7,8,9,10
2017/4/12
Kazi A Kalpoma
14
Prime Numbers
A: 0, and 1 not prime since not positive and greater or
equal to 2
2 is prime as 1 and 2 are only factors
3 is prime as 1 and 3 are only factors.
4,6,8,10 not prime as non-trivially divisible by 2.
5, 7 prime.
9 = 3 · 3 not prime.
Last example shows that not all odd numbers are
prime.
2017/4/12
Kazi A Kalpoma
15
Fundamental Theorem of Arithmetic
THM: Any number n  2 is expressible as a
unique product of 1 or more prime numbers.
Note: prime numbers are considered to be
“products” of 1 prime.
We’ll need induction and some more number
theory tools to prove this.
2017/4/12
Kazi A Kalpoma
16
Fundamental Theorem of Arithmetic
Q: Express each of the following number
as a product of primes: 22, 100, 12, 17
A:
2017/4/12
22 = 2·11,
12 = 2·2·3,
100 = 2·2·5·5,
17 = 17.1
Kazi A Kalpoma
17
Primality Testing
Some useful points for primality testing……
•
•
•
•
Don’t try number bigger than n/2
After trying 2, if it is not divisible by 2, don’t try any other even
numbers, because n is odd by this point.
In general, try only smaller prime numbers
In fact, only need to try to divide by prime numbers no larger
than n as we’ll see next:
2017/4/12
Kazi A Kalpoma
18
Example of Primality Testing.
EG: Test if 139 and 143 are prime.
List all primes up to n and check if they divide the numbers.
(2,3,5,7,11………..)
2: Neither is even
3: Sum of digits trick: 1+3+9 = 13, 1+4+3 = 8 so neither divisible by
3
5: Don’t end in 0 or 5, so not divisible by 5
7: 139 not divisible by 7, neither 143
11: Alternating sum trick: 1-3+9 = 7 so 139 not div. By 11. 1-4+3 =
0 so 143 is divisible by 11.
STOP! Next prime 13 need not be examined since bigger than n .
Conclude: 139 is prime, 143 is composite (not prime).
2017/4/12
Kazi A Kalpoma
19
Primality Testing
LEMMA: If n is a composite, then n has a prime factor 
2017/4/12
Kazi A Kalpoma
n
20
Greatest Common Divisor
Relatively Prime
DEF Let a,b be integers, not both zero. The greatest
common divisor of a and b (or gcd(a,b) ) is the
biggest number d which divides both a and b.
Equivalently: gcd(a,b) is smallest number which divisibly
by any x dividing both a and b.
DEF: a and b are said to be relatively prime if gcd(a,b)
= 1, so no prime common divisors.
2017/4/12
Kazi A Kalpoma
21
Greatest Common Divisor
Relatively Prime
Q: Find the following gcd’s:
1. gcd(11,77)
2. gcd(33,77)
3. gcd(24,36)
4. gcd(24,25)
2017/4/12
Kazi A Kalpoma
22
Greatest Common Divisor
Relatively Prime
A:
1.
11 = 1.11
77 = 1.77 = 7.11
gcd(11,77) = 11
2.
gcd(33,77) = 11
3.
gcd(24,36) = 12
4.
gcd(24,25) = 1. Therefore 24 and 25 are relatively prime.
NOTE: A prime number are relatively prime to all other numbers
which it doesn’t divide.
2017/4/12
Kazi A Kalpoma
23
Greatest Common Divisor
Relatively Prime
EG: More realistic. Find gcd(98,420).
Find prime decomposition of each number and find all
the common factors:
98 = 2·49 = 2·7·7
420 = 2·210 = 2·2·105 = 2·2·3·35
= 2·2·3·5·7
Underline common factors: 2·7·7, 2·2·3·5·7
Therefore, gcd(98,420) = 14
2017/4/12
Kazi A Kalpoma
24
Greatest Common Divisor
Relatively Prime
Pairwise relatively prime: the numbers a, b,
c, d, … are said to be pairwise relatively
prime if any two distinct numbers in the list
are relatively prime.
Q: Find a maximal pairwise relatively prime
subset of
{ 44, 28, 21, 15, 169, 17 }
2017/4/12
Kazi A Kalpoma
25
What is the Least Common Multiple (LCM) of 4
and 6?
• Multiples of 4 are:
4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56,
60, 64, 68, 72, 76, ...
• and the multiples of 6 are:
6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, ...
• Common multiples of 4 and 6 are simply
the numbers that are in both lists:
12, 24, 36, 48, 60, 72, ....
• So, from this list of the first few common
multiples of the numbers 4 and 6, their least
(lowest) common multiple is 12.
2017/4/12
Kazi A Kalpoma
26
Least Common Multiple
DEF: The least common multiple of a, and b
(lcm(a,b) ) is the smallest number m which is divisible
by both a and b.
Equivalently: lcm(a,b) is biggest number which divides
any x divisible by both a and b
Q: Find the lcm’s:
1.
2.
3.
2017/4/12
lcm(10,100)
lcm(7,5)
lcm(9,21)
Kazi A Kalpoma
27
Least Common Multiple
1.
lcm(10,100) = 100
2.
lcm(7,5) = 35
3.
lcm(9,21) = 63
THM: Let a and b be positive integers. Then
ab = gcd (a, b) . lcm (a, b)
i, e., lcm(a,b) = ab / gcd(a,b)
Using Euclidean algorithm
2017/4/12
Kazi A Kalpoma
28
Division algorithm
Remember long division?
d the
divisor
a the
dividend
3
31 117
93
24
q the
quotient
r the
remainder
117 = 31·3 + 24
The general form of a linear equation can be expressed as
a = dq + r
2017/4/12
Kazi A Kalpoma
29
Division
THM: Let a be an integer, and d be a positive integer.
There are unique integers q, r with r  {0,1,2,…,d1} satisfying
a = dq + r
The equation can be transformed to find the
remainder as:
r=a−q×d
However, a and d must be natural numbers, with d
being non-zero. The remainder must also be an
integer.
The theorem is called the division algorithm.
2017/4/12
Kazi A Kalpoma
30
Mod function
• In computing, the modulo (sometimes called
modulus) operation finds this remainder of
division (r = a − q × d ).
• Given two positive numbers, a (the dividend)
and d (the divisor), a modulo d (abbreviated
as a mod d) is the remainder of the
Euclidean division of a by d.
• The expression 5 mod 2=1
because 5 divided by 2 leaves a quotient of 2 and a
remainder of 1
2017/4/12
Kazi A Kalpoma
31
mod function
Q: Compute
1. 113 mod 24
2. -29 mod 7
2017/4/12
Kazi A Kalpoma
32
mod function
A: Compute
1. 113 mod 24:
=17
24 113
1. -29 mod 7
2017/4/12
Kazi A Kalpoma
33
mod function
A: Compute
1. 113 mod 24:
=17
1. -29 mod 7
2017/4/12
4
24 113
96
17
Kazi A Kalpoma
34
mod function
A: Compute
1. 113 mod 24:
=17
1. -29 mod 7
=6
4
24 113
96
17
7  29
2017/4/12
Kazi A Kalpoma
35
mod function
A: Compute
1. 113 mod 24:
=17
4
24 113
96
17
1. -29 mod 7
=6
5
7  29
 35
6
2017/4/12
Kazi A Kalpoma
36
Modular Arithmetic
There are two types of “mod” (confusing):
• the mod function
– Inputs a number a and a base b
– Outputs a mod b a number between 0 and b –1
inclusive
– This is the remainder of ab
• the (mod) congruence
– Relates two numbers a, a’ to each other relative
some base b
– a  a’ (mod b) means that a and a’ have the
same remainder when dividing by b
2017/4/12
Kazi A Kalpoma
37
(mod) Congruence (Formal Definition)
DEF: Let a, a’ be integers and b be a positive integer.
We say that a is congruent to a’ modulo b (denoted
by a  a’ (mod b) ) iff b | (a – a’ ).
Example: 9  1 (mod 2) since 2 | (9 - 1)
Equivalently: a mod b = a’ mod b
Q: Which of the following are true?
1.
2.
3.
4.
2017/4/12
3  3 (mod 17)
3  -3 (mod 17)
172  177 (mod 5)
-13  13 (mod 26)
Kazi A Kalpoma
38
(mod) congruence
A:
1. 3  3 (mod 17) True. any number is congruent to
itself (3-3 = 0, divisible by all)
2. 3  -3 (mod 17) False. (3-(-3)) = 6 isn’t divisible by
17.
3. 172  177 (mod 5) True. 172-177 = -5 is a
multiple of 5
4. -13  13 (mod 26) True: -13-13 = -26 divisible by
26.
2017/4/12
Kazi A Kalpoma
39
(mod) congruence
Identities
The (mod) congruence is useful for manipulating
expressions involving the mod function. It lets us
view modular arithmetic relative a fixed base, as
creating a number system inside of which all the
calculations can be carried out.
a mod b  a (mod b)
Suppose a  a’ (mod b) and c  c’ (mod b)
•
•
Then:
– a+c  (a’+c’ )(mod b)
– ac  a’c’ (mod b)
– a k  a’ k (mod b)
2017/4/12
Kazi A Kalpoma
40
• Important Applications of
Congruencies in computer science
and number theory--– Hashing Functions,
– Random number generation, and
– Cryptology.
2017/4/12
Kazi A Kalpoma
41
Psedorandom number generation
• Most commonly used procedure is linear
congruential method.
Xn+1 = (aXn +c)mod m
Here m = modulus
a = multiplier 2≤a<m
c = increment 0≤c<m and
X0 = seed
2017/4/12
Kazi A Kalpoma
42
Xn+1 = (aXn +c)mod m
2017/4/12
Kazi A Kalpoma
43
Cryptology
• It is the study of secrete messages.
• Caesar’s Cipher is one of the simplest and most widely
known encryption .
• He made messages secret by shifting each letter three letters
forward in the alphabet. For instance, using this scheme the letter
B is sent to the position of E and the letter X is sent to A position.
Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Cipher: XYZABCDEFGHIJKLMNOPQRSTUVW
• Caesar’s Cipher
f (a) = (a+3) mod 26
2017/4/12
Kazi A Kalpoma
44
Simple Encryption
Variations on the following have been used to encrypt
messages for thousands of years.
Steps:
Convert a message to capitals.
1. Think of each letter as a number between 1 and 26.
2.
Apply an invertible modular function to each
number. [A function ƒ that has an inverse is called
invertible]
3.
Convert back to letters (0 becomes 26).
2017/4/12
Kazi A Kalpoma
45
Letter  Number
Conversion Table
A B C D E
F G H I
J
K L
1 2 3 4 5 6 7 8 9 10 11 12
M N O
P
Q
R
S
T
U
V W X
Y
13 14 15 16 17 18 19 20 21 22 23 24 25
Z
26
2017/4/12
Kazi A Kalpoma
46
Encryption example
• Let the encryption function be Caesar’s
Cipher f (a) = (a+3) mod 26
Encrypt “I Love You”
•
•
•
•
2017/4/12
I LOVE YOU
9 12,15,22,5 25,15,21
12 15,18,25,8 2,18,24
L ORYH BRX
Kazi A Kalpoma
(capitals)
47
Simple Decryption:
Decryption works the same, except that you apply the
inverse function.
• The decryption of Caesar’s Cipher; the
inverse function is f (a) = (a - 3) mod 26
[We know the inverse of Add is Subtract]
Decrypt “L ORYH BRX”
•
•
•
•
2017/4/12
L ORYH BRX
12 15,18,25,8 2,18,24
9 12,15,22,5 25,15,21
I LOVE YOU
Kazi A Kalpoma
48
The Inverse
a mod m has an inverse a', if a.a’ ≡ 1 (mod m).
The inverse exists whenever a and m are relatively prime.
Example. What is the inverse of 3 mod 7?
Since gcd (3, 7) = 1, it has an inverse.
The inverse is -2 because 3.(-2) ≡ 1 mod 7
since 7 | 3.(-2)-1 i.e. 7 divides -7.
2017/4/12
Kazi A Kalpoma
49
Examples for Home work continuation…..
1. Find the inverse of 4 modulo 9.
2. Find the inverse of 2 modulo 17.
3. Find the inverse of 19 modulo 141.
4. Find the inverse of 144 modulo 233.
2017/4/12
Kazi A Kalpoma
50
Encryption example (more)….
Let the encryption function be
f (a) = (3a + 9) mod 26
Encrypt “Stop Thief”
1.
2.
3.
4.
2017/4/12
STOP THIEF
(capitals)
19,20,15,16 20,8,9,5,6
14,17,2,5 17,7,10,24,1
NQBE QGJXA
Kazi A Kalpoma
51
Decryption example
•
Decryption works the same, except that you apply the
inverse function.
EG: Find the inverse of
f (a) = (3a + 9) mod 26
If we didn’t have to deal with mod 26, inverse would be
g (a) = 3-1 (a - 9)
We’ll see that since gcd(3, 26) = 1, the inverse of 3
with modulo 26 is possible and the inverse number is 9.
(Since 3.9 ≡ 1 mod 26 and 26|3.9-1)
This gives:
g (a) = 9 (a - 9) mod 26 = (9a – 3) mod 26
2017/4/12
Kazi A Kalpoma
52
We know the inverse of Multiply is Divide, and the
inverse of Add is Subtract
• Here we have the function f(a) = 3a+9, written as
a flow diagram:
a
Multiply by 3
3a
Add 9
3a+9
• The Inverse Function just goes the other way:
(a-9)/3
a-9
subtract 9
Divide by 3
a
• 3-1(a-9) mod 26= 9(a-9)mod 26 = (9a – 3) mod 26
2017/4/12
Kazi A Kalpoma
53
Decryption example
• Now decrypt the encrypted message
NQBE QGJXA when the encrypted
function was f (a) = (3a + 9) mod 26.
i.e. the inverse function will be
f (a) = (9a - 3) mod 26
The result will be
STOP THIEF
2017/4/12
Kazi A Kalpoma
54
Example
•
•
2017/4/12
Encrypt the message “DO NOT PASS
GO” by translating the letters into
numbers, applying the encryption
function given, and then translating
the numbers back into letters.
• F (p) = (p+3) mod 26 (Caesar
cipher)
Decrypt the message that encrypted
using the Caesar cipher in above.
Kazi A Kalpoma
55
Examples for Home work
1.
Encrypt the message “ DO NOT PASS GO” by
translating the letters into numbers, applying the
encryption functions given and then translating the
numbers back into letters
a) f (a) = (a + 3) mod 26
b) f (a) = (a + 13) mod 26
c) f (a) = (3a + 7) mod 26
2.
Decrypt the messages encrypted using the Caesar
Cipher [f (a) = (a - 3) mod 26]
a) EOXH MHDQV
b) WHVW WRGDB
2017/4/12
Kazi A Kalpoma
56
Linear Congruences
• A congruence of the form ax
 b (mod m)
where m is a positive of the form, a and b
are integers, and x is a variable, is called
a linear congruence.
• Congruences arise throughout number
theory and its application.
2017/4/12
Kazi A Kalpoma
57
Examples:
• What are the solutions of linear
congruence
x  5 (mod 6)?
• What are the solutions of linear
congruence
2017/4/12
3x 
4 (mod 7)?
Kazi A Kalpoma
58
Modular multiplicative inverse
• The modular multiplicative inverse of an
integer a modulo m is an integer x such that
• The multiplicative inverse of a modulo m
exists if and only if a and m are coprime (i.e.,
if gcd(a, m) = 1).
• If the modular multiplicative inverse of a
modulo m exists, the operation of division by
a modulo m can be defined as multiplying
by the inverse
2017/4/12
Kazi A Kalpoma
59
Example:
• Suppose we wish to find modular multiplicative
inverse x of 3 mod 11.
• This is the same as finding x such that
• Working in
we find one value of x that satisfies
this congruence is 4 because
• and there are no other values of x in that satisfy
this congruence. Therefore, the modular
multiplicative inverse of 3 mod 11 is 4.
2017/4/12
Kazi A Kalpoma
60