Math Theorems Flashcards

1
Q

Using Fermats Little Theorem how can we avoid testing every number 1 to P

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What theorem would you use to solve:

wx - yx divisible by N

if

  1. N can be factored into two primes
  2. GCD(w,N) = 1 and GCD(y,N) = 1
A

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!!!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the substitution rule for x and y

in modulo arithmetic in terms of x’ and y’

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Can you prove that if a mod b has an inverse then b mod a must also have an inverse?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Euler’s Theorem

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Multiply Algorithm

Time O(n2)

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How can we use Fermats Little Theorem to prove a number is prime.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Euclid’s Rule

A

if x & y are positive integers x >= y,

then gcd(x,y) = gcd(x mod y, y)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How are keys created for RSA

A

1. Pick two large prime numbers p and q

  1. calculate n = pq. (n is the modulus for pub and priv)
  2. Calculate totient of n .. (p-1)(q-1)
  3. Choose e (the public key exponent) so that the gcd(e, totient(n)) = 1. (can be small like 3, 5, 35)
  4. Calculate d to be the inverse of e mod totient(n)
    1. Use Extended-Euclid (e,n)
    2. The number that returns as the multiple (x) for e is the inverse.
    3. if it’s negative you need to mod it. (Basically add N to it until it is positive.)
    4. 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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

ModExp Algorithm

Time O(n3)

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is Euclid’s Algorithm for GCD

Time O(n3)

A

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 =>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

if x & y are positive

x >= y

then

gcd(x,y) is equal to

A

gcd(y, x mod y)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

p is prime, q is prime:

N = pq

What is totient(N)

A

(p-1)(q-1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Big O time for modulo

Addition

Multiplication

Division

A

Addition => O(n)

Multiplication => O(n2)

Division => O(n3)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is multiplicative inverse for modulo numbers?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Divide Algorithm

Time O(n2)

A

Divide(x,y):

if x = 0: return (q,r) = (0,0)

(q,r) = divide(floor(x/2), y)

q = 2 * q, r = 2 * r

if x is odd:

r = r + 1

if r >= y:

r= r - y

q = q + 1

return (q, r)

17
Q

What is Eculid’s Extended Algorithm

(and what can you tell with it)

A

To check if a number d is the gcd of a and b. Then the extension says:

if d divides both a and b, and d = ax + by for some integers x and y then necessarily d = gcd (a,b)

extended-euclid(a,b):

input a,b with a>=b>=0

output: x, y, d such that d = gcd(a,b) and ax + by = d

if b = 0: return (1,0,a)

(x’, y’, d) = extended-Euclid(b, a mod b)

return (y’, x’ - floor(a/b)y’, d)

18
Q

Euler’s Totient Function

A

For prime P, Totient(P) = P - 1;

When N = pq, Totient(N) = (p-1)(q-1)

19
Q

How can you reduce 2345 (mod 31)

using the substitution rules and associativity, commutativity and distributivity

A

Taken together with the substitution rule, it is legal to reduce intermediate results modulo N at any stage. So simplifications can be made like:

2345 (mod 31) ==>

(25)69 (mod 31) ==>

3269 (mod 31) ==>

169 (mod 31) ==>

1 (mod 31)

20
Q

What theorem would you use to solve

a mod N

if N is prime.

A

Fermats Little Theorem

(If N is prime, than for 1 <= a < n)

a(n-1) = 1 mod N

199 (mod 5)

19(5-1) => 194 = 1 mod 5

Divide exponent by N-1:

9/4 = 2 R 1

This means 198 = 1 mod 5

Substiution leaves

198 (mod 5) * 191 (mod 5) => 1 (mod 5) * 19 mod 5

1 * 4 = 4

21
Q

How is RSA performed using:

N, e -> public key

d -> private key

A

Encrypt x:

y = xe mod N

Decrypt y:

x = yd mod N

22
Q

Fermat’s Little Theorem

A

If p is prime, then for every 1 <=a < p

ap-1 = 1 (mod p)

e.g: is 2^2 = 1 mod 3

p = 3 and is prime

2^(3-1) = 2^2 = 1 mod 3

1 mod 3

23
Q

How do you get a prime number?

A

Select a random n bit number

Run it through flt

if passes it is prime, otherwise try again

Probability of hitting a prime in n but numbers is 1/n so we expect this to only take n guesses at most.

24
Q

What are the 3 main steps to Kruskal’s Algorithm

Time: O(mlogn)

m = edges

n = verticies

A

Input: Undireted graph G(v,e) with weights w(e)

  1. Sort E by increasing weight
  2. Set x to the empty set.
  3. For each edge in our sorted list of edges, if adding edge into x does not create a cycle, then add the edge.
  4. Return x
25
Q

What are cut edges

Undirected G=(v,e)

Partition V = S union ~S

A

Cut(S,~S) = {(v,w) in E: v in S, w in ~s}

This says cut edges are the edges that

cross between S and ~S.

26
Q

2 Takeaway’s from MST proof

A

1) I can take a tree, add in e* and that creates a cycle. I can then remove any edge from that cycle and get a new tree T’
2) A minimum weight edge across the cut is part of a mst.

27
Q

What is topological order in an acyclic graph

A

The order based on decreasing post number.