-
Notifications
You must be signed in to change notification settings - Fork 0
/
TD_MR.py
48 lines (40 loc) · 1.29 KB
/
TD_MR.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from random_number import getRandom
from trial_division import checkTrialDivision
from miller_robin_test import miller_rabin
from generate_k_primes import kPrimes
import timeit
import matplotlib.pyplot as plt
from gcd_finder import computeGCD, computeGCDMR
# TD-MR Combination(n, k)
# 1) Random Number Generation
# - Generate an n-bit odd random number r.
# 2) Trial division on r with k primes <= sqrt(n)
# - Divides r by k small primes.
# - If r is divided by any prime, go to Step 1.
# 3) Miller-Rabin test on r
# - Perform Miller-Rabin Test on r.
# - If r passes, return r as a prime.
# - Otherwise, go to Step 1.
def combinationTD_MR(n, primes):
k=100
while True:
# 1) Random Number Generation
# - Generate an n-bit odd random number r.
r = getRandom(n)
#print(r)
#t = r* r * r
#return r
# 2) Trial division on r with k primes
# - Divides r by k small primes.
# - If r is divided by any prime, go to Step 1.
if(checkTrialDivision(r, primes) == False):
continue
#print(False)
# 3) Miller-Rabin test on r0
# - Perform Miller-Rabin Test on r.
# - If r passes, return r as a prime.
# - Otherwise, go to Step 1.
if(miller_rabin(r) == False):
#print(False)
continue
return r