Math Theorems Flashcards
Using Fermats Little Theorem how can we avoid testing every number 1 to P
for a single number
Prob that flt returns yes when N is prime is 1
Prob that flt returns yes when N is not prime is <= 1/2
So depending on the amount of certainty we pick k different a values, which gives us
1/2k as the probability flt returns yes when it is not prime.
What theorem would you use to solve:
wx - yx divisible by N
if
- N can be factored into two primes
- GCD(w,N) = 1 and GCD(y,N) = 1
Euler’s Theorem:
If N is the product of 2 prime numbers and GCD(w,Z) = 1 and GCD(y,Z) = 1
Then Z(p-1)(q-1) === 1 mod N
E.g. Is 41536 - 94824 divisible by 35
35 is product of 5 & 7 (two primes)
gcd(4,35) = 1
gcd(9,35) = 1
(p-1)(q-1) = (5-1) * (7-1) = 24
Z24 = 1 mod 35
1536/24 = 64 so 4(24*64) equals 1 mod 55
4824/24 = 201 so 9(24)(201) equals 1 mod 9
1 mod 5 = 1, 1 mod 9 = 1
1 -1 = 0, there is no left over so yes it is divisible!!!
What is the substitution rule for x and y
in modulo arithmetic in terms of x’ and y’
if
x = x’ (mod n) and y = y’ (mod n)
then
x + y === x’ + y’ (mod n)
and
xy === x’y’ (mod n)
10 * 15 (mod 4) =>
(10 (mod 4) * 15) (mod 4) -or-
(10 * 15 (mod 4)) (mod 4)-or-
(10 (mod 4) * 15 (mod4)) (mod 4)
Can you prove that if a mod b has an inverse then b mod a must also have an inverse?
Yes, a (mod b) only has an inverse if gcd (a,b) = 1
so the formula b (mod a) only has an inverse if gcd(b,a) = 1
gcd(a,b) and gcd(b,a) are the same formula.
Euler’s Theorem
For N = pq where p & q are prime,
For any Z where gcd(Z, N) = 1
Then Z(p-1)(q-1) is equivliant to 1 mod N
Multiply Algorithm
Time O(n2)
Multiply(x,y):
if y == 0: return 0
z = multiply(x, floor(y/2))
if y is even:
return 2z
else
return x + 2z
How can we use Fermats Little Theorem to prove a number is prime.
Fermat’s little theorem says:
If p is prime, then for every 1 <=a
a(p-1) === 1 (mod p)
So if we have a number P that we want to test for primality, then calculate
a(p-1) for every value a between 1 and p.
If they all equal 1, then it is prime.
(Note: There are some charmichael numbers like 561 which pass the test, but aren’t prime.
Euclid’s Rule
if x & y are positive integers x >= y,
then gcd(x,y) = gcd(x mod y, y)
How are keys created for RSA
1. Pick two large prime numbers p and q
- calculate n = pq. (n is the modulus for pub and priv)
- Calculate totient of n .. (p-1)(q-1)
- Choose e (the public key exponent) so that the gcd(e, totient(n)) = 1. (can be small like 3, 5, 35)
- Calculate d to be the inverse of e mod totient(n)
- Use Extended-Euclid (e,n)
- The number that returns as the multiple (x) for e is the inverse.
- if it’s negative you need to mod it. (Basically add N to it until it is positive.)
- This number alone not (x * e) but the x is the inverse x Mod N.
Public Key = (n, e)
Private key = (d)
Note if you get a decryption key of 1, then your selection of e was not gcd 1 with totn.
ModExp Algorithm
Time O(n3)
ModExp(x, y, N):
if y = 0: return 1
Z = modexp(x, floor(y/2), N)
if y is even:
return z2 mod N
else
return x * z2 mod N
What is Euclid’s Algorithm for GCD
Time O(n3)
Euclid(a,b):
// a and b with a >= b >= 0
if b = 0: return a
return Euclid(b, a mod b)
b, a mod b =>
if x & y are positive
x >= y
then
gcd(x,y) is equal to
gcd(y, x mod y)
p is prime, q is prime:
N = pq
What is totient(N)
(p-1)(q-1)
Big O time for modulo
Addition
Multiplication
Division
Addition => O(n)
Multiplication => O(n2)
Division => O(n3)
What is multiplicative inverse for modulo numbers?
x is the multiplicative inverse of a (mod n)
if a*x (mod n) = 1
Sometimes one doesn’t exist. if gcd(a, N) > 1, it can never exist. E.g. a=2, N=6
When gcd(a, N) = 1 (we say a and N are relatively prime), the extended Euclid algorithm gives us integers x and y such that ax + N y = 1, which means that ax ≡ 1 (mod N). Thus x is a’s sought inverse.