Exemplo n.º 1
0
  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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
 def testBrentComposite(self):
   random_obj = intalg.MiniIntRandom(42)
   for n in intalg.yield_composites():
     if n > 100000:
       break
     b = intalg.brent(n, random_obj)
     assert b > 1
     assert b <= n
     self.assertEquals(0, n % b, (b, n))
Exemplo n.º 4
0
 def testBrentComposite(self):
     random_obj = intalg.MiniIntRandom(42)
     for n in intalg.yield_composites():
         if n > 100000:
             break
         b = intalg.brent(n, random_obj)
         assert b > 1
         assert b <= n
         self.assertEquals(0, n % b, (b, n))
Exemplo n.º 5
0
 def testBrentPrime(self):
   random_obj = intalg.MiniIntRandom(42)
   for n in intalg.primes_upto(100000):
     b = intalg.brent(n, random_obj)
     self.assertEquals(b, n)
Exemplo n.º 6
0
 def testBrentPrime(self):
     random_obj = intalg.MiniIntRandom(42)
     for n in intalg.primes_upto(100000):
         b = intalg.brent(n, random_obj)
         self.assertEquals(b, n)