Example #1
0
 def testKnowPrimes(self):
     """ Test a few known primes """
     for prime in knownPrimes:
         for testNum in (2, 3, 5, 7, 9, 13, 17, 19, 21, 27, 33, 101, 205):
             assert (
                 rabin_miller(prime, testNum)
             ), 'Prime: %d should pass rabin miller test using %d!' % (
                 prime, testNum)
Example #2
0
 def testKnowComposites(self):
     """ Test a few known primes """
     for nonPrime in knownComposites:
         witness = 1
         for testNum in (2,3,5,7,9,13,17,19,21,27,33,101,205):
             if not rabin_miller(nonPrime, testNum):
                 witness = 0
             #print witness, nonPrime, testNum
         assert( not witness ), 'NonPrime: %d should Fail rabin miller tests!'%nonPrime
Example #3
0
 def testKnowComposites(self):
     """ Test a few known primes """
     for nonPrime in knownComposites:
         witness = 1
         for testNum in (2, 3, 5, 7, 9, 13, 17, 19, 21, 27, 33, 101, 205):
             if not rabin_miller(nonPrime, testNum):
                 witness = 0
             #print witness, nonPrime, testNum
         assert (
             not witness
         ), 'NonPrime: %d should Fail rabin miller tests!' % nonPrime
Example #4
0
 def test50K(self):
     """ Test all composites below the first 50000 primes
         print out the maxium witness number required """
     f=open('primes_1st_50k.txt','r')
     s=f.read()
     f.close()
     ps=split(s)
     primes_1st_50k = [atoi(i) for i in ps]
     maxWitness = 2
     lastPrime = 2
     for prime in primes_1st_50k[1:]:
         for composite in range(lastPrime+2,prime,2):
             for witness in primes_1st_50k:
                 if not rabin_miller(composite, witness):
                     if witness > maxWitness:
                         maxWitness = witness
                         print 'composite, maxWitness',composite,maxWitness
                     lastPrime = prime
                     break
             #assert(witness!=primes_1st_50K[-1]),'MR test failed!!!!!!!'
         lastPrime = prime
     print 'last tested',prime
Example #5
0
 def test50K(self):
     """ Test all composites below the first 50000 primes
         print out the maxium witness number required """
     f = open('primes_1st_50k.txt', 'r')
     s = f.read()
     f.close()
     ps = split(s)
     primes_1st_50k = [atoi(i) for i in ps]
     maxWitness = 2
     lastPrime = 2
     for prime in primes_1st_50k[1:]:
         for composite in range(lastPrime + 2, prime, 2):
             for witness in primes_1st_50k:
                 if not rabin_miller(composite, witness):
                     if witness > maxWitness:
                         maxWitness = witness
                         print 'composite, maxWitness', composite, maxWitness
                     lastPrime = prime
                     break
             #assert(witness!=primes_1st_50K[-1]),'MR test failed!!!!!!!'
         lastPrime = prime
     print 'last tested', prime
Example #6
0
 def testKnowPrimes(self):
     """ Test a few known primes """
     for prime in knownPrimes:
         for testNum in (2,3,5,7,9,13,17,19,21,27,33,101,205):
             assert( rabin_miller(prime, testNum) ), 'Prime: %d should pass rabin miller test using %d!'%(prime,testNum)