Number Theory
Number Theory
Ex : 3 mod 10 = 3
13 mod 10 = 3
16 mod 10 = 6
(a+kn)+(b+ln) = a + b + (k+l)n = a + b
Primes
• A number is prime iff it is divisible by 2 posi3ve integers (itself and 1 ): 2,3,5,7,11,,13,17,…….
• There are ∞ number of primes
prove :
Euclid’s Algorithm
Used to :
ex : gcd ( 8,12) = 4
Euclid’s algorithm :-
to find gcd (x,y ) : replace original numbers with smaller that have same gcd until one of the number is
zero ( repeated )
<x,y> and < x-y,y> have same common divisors so replace x with its remainder when divided by y
How Euclid’s algorithm can be used to find the multiplicative inverse values?
um mod n=1 or
um=1 mod n or
um +vn=1
Steps :
1- gcd(m,n)
2- Try to find u,v such that the provided gcd (m,n) =1 (m,n are relatively prime numbers)
note if m,n are not relative prime , then m doesn’t have a multiplicative inverse mode n
Question: Could there be more than one u mod n for which um mod n = 1
408/187 =2 remainder 34
187 / 34 = 5 remainder 17
Algorithm:-
Initial set up
N Qn Rn Un Vn
-2 X 408 1 0
-1 Y 595 0 1
0 0 408 1 0
1 1 187 -1 1
2 2 34 3 -2
3 5 17 -16 11
4 2 0 35 -24
Rn =unx + vny
1- Initial set up :- u-2 =1 , v-2 =0
u-1 = 0 , v-1 = 1
2- At step n :-
un = un-2 – qnun-1
Vn= vn-2 – qnvn-1
Since r4 = 0 we can read n=3
gcd ( 408,595) =r3 =17=-16 x 408 + 11 x 595
Summary :
If m,n are relatively prime, we can use Euclid’s algorithm to find u ( and v ) in a way such that:
n qn rn un vn
-2 797 1 0
-1 1074 0 1
0 0 797 1 0
1 1 250 -1 1
2 3 47 4 -3
3 5 15 -21 16
4 3 2 67 -15
5 7 1 -490 373
and x2 mod z2
.. ..
Xk mod zk
Also if something equals x mod z1 z2 z3 …..zk , then you can calculate what number is mod z1 & mod z2
Therefore:
Example mul3plying by 5 half the numbers would encrypt to 0’s and the other half would encrypt to 5’s
Multiplication inverse of x (written x -1 ) is the number by which you mul3ply x to get 1 ( in ordinary
arithme3c x’s mul3plica3ve inverse is 1/x )
Only the numbers { 1,3,7,9} have mul3plica3ve inverse mod 10. For example 7 is the mul3plica3ve
inverse of 3 ( 7*3 mod 10 =1)
Now, what if n was a 100 digit number? how would we able to find multiplicative inverse ?
We can’t use brute force search, but there is an algorithm that will find “inverse mod n”. It is known as
Euclid’s algorithm :
Question: what is so special about numbers { 1,3,7,9} ? Why they are the only ones? The answer that
those numbers are rela3vely prime to n (10)
In general when you are working with n, then all the numbers that are relatively prime to n will have
multiplicative inverse
ф (n) : Totient function tells ( total + quotient ) :- if n is prime then all the integers { 1,2,…….n } are
relatively prime to n ф(n) = n-1
more over if we have 2 primes say p,q, then there are ( p-1) ( q-1) numbers rela3vely prime to n
ф(n) = ( p-1 ) ( q-1) why is that ?
well, there are n= pq ; total numbers in { 0,1,2,……..n-1 }, and we want to exclude those numbers that
aren’t relatively prime to n. Those are the numbers that are either multiples of p or multiples of q. Then
there are p multiple of q less than pq and q multiple of p less than pq. Those are p+q -1 numbers less
than pq that aren’t relatively prime to pq ( we cant count 0 twice ) -> ф ( pq) = pq – ( p+q-1) = (p-1) ( q-1)
Example p=3 q=7 -> ф(n) =12 12 numbers less than n are rela3vely prime to 21
1,2,4,5,8,,10,11,13,16,17,18,20
Modular Exponentiation
Example 46 mod 10 = 4096 mod 10 = 6 mod 10
Note exponen3a3on by 3 would act as an encryption of the digits because it rearranges all the digits
So that the ith column in the above table is the same as the I + 4th column ( column # 1 = column#5 &
column#3 = column#7, and so on )
Col.5 = col.1
Encryption / decryption :
& 7=3+ф(n)
Note 2,6 ( 2,2+ф(n)) can’t work as crypto system because they are not prime numbers
1 3 7 9
1 1 3 7 9
3 3 9 1 7
7 7 1 9 3
9 9 7 3 1
Observation :
1. All answers are either 1,3,7 or 9 i.e if you mul3ply any two numbers in Z10* you get another
number in Z10*
2. Each row column contain all elements of Z10* with no repeat
3. It is not only true for 10, but any no ( try 15) Z15* = { 1,2,4,7,8,11,13,14}
Modular Addition
Now look at mod 10 addi3on table, it can be used as a scheme for encrypting digits ( it maps each
decimal digit to a different decimal digit in a way that is reversible )
The constant is our secret key it is not a good cipher but it is a cipher ( it is actually a ceaser cipher )
Iif a secret key were 4 then to encrypt we would add 4(mod 10), to decrypt we would add 6(mod 10)
So for encryp3ng and decryp3ng we can use (6, 4) & (7,3) “Called additive inverse”
all public key algorithm have in common pair of keys one secret and one public
modular arithmetic
.. … .. ..
Euler’s theorem:
Proof :-
•Multiply each element of Zn* by a and multiply all those together the result will be
aф(n) x = x ( since the product just rearrange the results )4
• X-1 therefore aф(n) =1
2. Euler’s theorem variant : for all a in Zn* and any integer k , akф(n)+1= a mod n
Variant : raising any number m to the power kф(n)+1 gets m back mod n ( works only for m in Zn* )
akф(n)+1 = a mod n
aф(p) = 1 mod p
akф(n)+1 = a mod p
akф(n)+1= a mod n