def testFactorizeLargePrimes(self): random_obj = intalg.MiniIntRandom(42) for ps in ([1073741827, 1152921504606847009], [34359738421, 1180591620717411303449], [7, 1763668414462081], [100003], [10000000019], [1000000000039], # Slow but tolerable. [10000000019] * 9, [1000000007] * 10, [1000000007] + [1000000009] * 2 + [1000000021] * 3): n = 1 for p in ps: n *= p divisors = set() # All divisors based on ps, except for 1. for i in xrange(1, 1 << len(ps)): r = 1 for j in xrange(0, len(ps)): if i & (1 << j): r *= ps[j] divisors.add(r) r = intalg.brent(n, random_obj) assert r in divisors r = intalg.pollard(n, random_obj) assert r in divisors sps = intalg.finder_slow_factorize(n) assert sps == ps, (n, sps, ps) sps = intalg.factorize(n) assert sps == ps, (n, sps, ps)
def testFactorizeSmall(self): for n in xrange(1, 100025): a = list(intalg.yield_slow_factorize(n)) b = intalg.finder_slow_factorize(n) c = intalg.factorize(n, divisor_finder=intalg.brent) d = intalg.factorize(n, divisor_finder=intalg.pollard) assert a == b == c == d, (n, a, b, c, d)
def testFactorizeLargePrimes(self): random_obj = intalg.MiniIntRandom(42) for ps in ( [1073741827, 1152921504606847009], [34359738421, 1180591620717411303449], [7, 1763668414462081], [100003], [10000000019], [1000000000039], # Slow but tolerable. [10000000019] * 9, [1000000007] * 10, [1000000007] + [1000000009] * 2 + [1000000021] * 3): n = 1 for p in ps: n *= p divisors = set() # All divisors based on ps, except for 1. for i in xrange(1, 1 << len(ps)): r = 1 for j in xrange(0, len(ps)): if i & (1 << j): r *= ps[j] divisors.add(r) r = intalg.brent(n, random_obj) assert r in divisors r = intalg.pollard(n, random_obj) assert r in divisors sps = intalg.finder_slow_factorize(n) assert sps == ps, (n, sps, ps) sps = intalg.factorize(n) assert sps == ps, (n, sps, ps)
def testFactorizeMedium(self): n = intalg.next_prime(intalg._SMALL_PRIME_LIMIT) ** 2 - 10 limit = n + 20025 while n < limit: # xrange can't take a long (n). a = list(intalg.yield_slow_factorize(n)) b = intalg.finder_slow_factorize(n) c = intalg.factorize(n) c = intalg.factorize(n, divisor_finder=intalg.brent) d = intalg.factorize(n, divisor_finder=intalg.pollard) assert a == b == c == d, (n, a, b, c, d) n += 1
def testFactorizeMedium(self): n = intalg.next_prime(intalg._SMALL_PRIME_LIMIT)**2 - 10 limit = n + 20025 while n < limit: # xrange can't take a long (n). a = list(intalg.yield_slow_factorize(n)) b = intalg.finder_slow_factorize(n) c = intalg.factorize(n) c = intalg.factorize(n, divisor_finder=intalg.brent) d = intalg.factorize(n, divisor_finder=intalg.pollard) assert a == b == c == d, (n, a, b, c, d) n += 1