Esempio n. 1
0
 def test_with_big_composites(self):
     # NextPrime[2^256]-2 (factors: 71, 1559, 4801, 7703, 28286...8993)
     self.assertFalse(
         isPrime(
             115792089237316195423570985008687907853269984665640564039457584007913129640233
             - 2))
     # NextPrime[2^256]+2 (factors: 3^2, 5, 7, 11, 1753, 19063..7643)
     self.assertFalse(
         isPrime(
             115792089237316195423570985008687907853269984665640564039457584007913129640233
             + 2))
     # NextPrime[2^1024]-2
     self.assertFalse(
         isPrime(
             179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137859
             - 2))
     # NextPrime[2^1024]+2
     self.assertFalse(
         isPrime(
             179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137859
             + 2))
     # NextPrime[NextPrime[2^512]]*NextPrime[2^512]
     self.assertFalse(
         isPrime(
             179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639477074095512480796227391561801824887394139579933613278628104952355769470429079061808809522886423955917442317693387325171135071792698344550223571732405562649211
         ))
 def test_with_big_composites(self):
     # NextPrime[2^256]-2 (factors: 71, 1559, 4801, 7703, 28286...8993)
     self.assertFalse(isPrime(115792089237316195423570985008687907853269984665640564039457584007913129640233-2))
     # NextPrime[2^256]+2 (factors: 3^2, 5, 7, 11, 1753, 19063..7643)
     self.assertFalse(isPrime(115792089237316195423570985008687907853269984665640564039457584007913129640233+2))
     # NextPrime[2^1024]-2
     self.assertFalse(isPrime(179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137859-2))
     # NextPrime[2^1024]+2
     self.assertFalse(isPrime(179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137859+2))
     # NextPrime[NextPrime[2^512]]*NextPrime[2^512]
     self.assertFalse(isPrime(179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639477074095512480796227391561801824887394139579933613278628104952355769470429079061808809522886423955917442317693387325171135071792698344550223571732405562649211))
Esempio n. 3
0
 def test_with_big_primes(self):
     # NextPrime[2^256]
     self.assertTrue(
         isPrime(
             115792089237316195423570985008687907853269984665640564039457584007913129640233
         ))
     # NextPrime[2^1024]
     self.assertTrue(
         isPrime(
             179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137859
         ))
 def test_with_big_primes(self):
     # NextPrime[2^256]
     self.assertTrue(isPrime(115792089237316195423570985008687907853269984665640564039457584007913129640233))
     # NextPrime[2^1024]
     self.assertTrue(isPrime(179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137859))
    def test_with_hard_primes_to_test(self):

        # XXX Rabin-Miller fails to properly detect following composites
        with self.assertRaises(AssertionError):
            for i in range(100):
                # OEIS A014233
                self.assertFalse(isPrime(2047))
                self.assertFalse(isPrime(1373653))
                self.assertFalse(isPrime(25326001))
                self.assertFalse(isPrime(3215031751))
                self.assertFalse(isPrime(2152302898747))
                self.assertFalse(isPrime(3474749660383))
                self.assertFalse(isPrime(341550071728321))
                self.assertFalse(isPrime(341550071728321))
                self.assertFalse(isPrime(3825123056546413051))
                self.assertFalse(isPrime(3825123056546413051))
                self.assertFalse(isPrime(3825123056546413051))
 def test_with_small_composites(self):
     self.assertFalse(isPrime(4))
     self.assertFalse(isPrime(6))
     self.assertFalse(isPrime(9))
     self.assertFalse(isPrime(10))
 def test_with_small_primes(self):
     self.assertTrue(isPrime(3))
     self.assertTrue(isPrime(5))
     self.assertTrue(isPrime(7))
     self.assertTrue(isPrime(11))
 def test_getRandomSafePrime(self):
     r = getRandomSafePrime(20)
     self.assertEqual(numBits(r), 20)
     self.assertTrue(isPrime(r))
     self.assertTrue(isPrime((r-1)//2))
 def test_getRangomPrime(self):
     r = getRandomPrime(20)
     self.assertEqual(numBits(r), 20)
     self.assertTrue(isPrime(r))
    def test_with_hard_primes_to_test(self):

        # XXX Rabin-Miller fails to properly detect following composites
        with self.assertRaises(AssertionError):
            for i in range(100):
                # OEIS A014233
                self.assertFalse(isPrime(2047))  # base 1
                self.assertFalse(isPrime(1373653))  # base 2
                self.assertFalse(isPrime(25326001))  # base 3
                self.assertFalse(isPrime(3215031751))  # base 4
                self.assertFalse(isPrime(2152302898747))  # base 5
                self.assertFalse(isPrime(3474749660383))  # base 6
                self.assertFalse(isPrime(341550071728321))  # base 7
                self.assertFalse(isPrime(341550071728321))  # base 8
                self.assertFalse(isPrime(3825123056546413051))  # base 9
                self.assertFalse(isPrime(3825123056546413051))  # base 10
                self.assertFalse(isPrime(3825123056546413051))  # base 11
                # Zhang (2007)
                self.assertFalse(isPrime(318665857834031151167461))  # base 12
                self.assertFalse(isPrime(3317044064679887385961981))  # base 13
                # base 14
                self.assertFalse(isPrime(6003094289670105800312596501))
                # base 15
                self.assertFalse(isPrime(59276361075595573263446330101))
                # base 16
                self.assertFalse(isPrime(564132928021909221014087501701))
                # base 17
                self.assertFalse(isPrime(564132928021909221014087501701))
                # base 18
                self.assertFalse(isPrime(1543267864443420616877677640751301))
                # base 19
                self.assertFalse(isPrime(1543267864443420616877677640751301))
                # F. Arnault "Constructing Carmichael Numbers Which Are Strong
                # Pseudoprimes to Several Bases". Journal of Symbolic
                # Computation. 20 (2): 151-161. doi:10.1006/jsco.1995.1042.
                # Section 4.4 Large Example (a pseudoprime to all bases up to
                # 300)
                p = int("29 674 495 668 685 510 550 154 174 642 905 332 730 "
                        "771 991 799 853 043 350 995 075 531 276 838 753 171 "
                        "770 199 594 238 596 428 121 188 033 664 754 218 345 "
                        "562 493 168 782 883".replace(" ", ""))
                self.assertTrue(isPrime(p))
                self.assertFalse(p * (313 * (p - 1) + 1) * (353 * (p - 1) + 1))
Esempio n. 11
0
    def test_with_hard_primes_to_test(self):

        # XXX Rabin-Miller fails to properly detect following composites
        with self.assertRaises(AssertionError):
            for i in range(100):
                # OEIS A014233
                self.assertFalse(isPrime(2047))  # base 1
                self.assertFalse(isPrime(1373653))  # base 2
                self.assertFalse(isPrime(25326001))  # base 3
                self.assertFalse(isPrime(3215031751))  # base 4
                self.assertFalse(isPrime(2152302898747))  # base 5
                self.assertFalse(isPrime(3474749660383))  # base 6
                self.assertFalse(isPrime(341550071728321))  # base 7
                self.assertFalse(isPrime(341550071728321))  # base 8
                self.assertFalse(isPrime(3825123056546413051))  # base 9
                self.assertFalse(isPrime(3825123056546413051))  # base 10
                self.assertFalse(isPrime(3825123056546413051))  # base 11
                # Zhang (2007)
                self.assertFalse(isPrime(318665857834031151167461))  # base 12
                self.assertFalse(isPrime(3317044064679887385961981))  # base 13
                # base 14
                self.assertFalse(isPrime(6003094289670105800312596501))
                # base 15
                self.assertFalse(isPrime(59276361075595573263446330101))
                # base 16
                self.assertFalse(isPrime(564132928021909221014087501701))
                # base 17
                self.assertFalse(isPrime(564132928021909221014087501701))
                # base 18
                self.assertFalse(isPrime(1543267864443420616877677640751301))
                # base 19
                self.assertFalse(isPrime(1543267864443420616877677640751301))
                # F. Arnault "Constructing Carmichael Numbers Which Are Strong
                # Pseudoprimes to Several Bases". Journal of Symbolic
                # Computation. 20 (2): 151-161. doi:10.1006/jsco.1995.1042.
                # Section 4.4 Large Example (a pseudoprime to all bases up to
                # 300)
                p = int("29 674 495 668 685 510 550 154 174 642 905 332 730 "
                        "771 991 799 853 043 350 995 075 531 276 838 753 171 "
                        "770 199 594 238 596 428 121 188 033 664 754 218 345 "
                        "562 493 168 782 883".replace(" ", ""))
                self.assertTrue(isPrime(p))
                self.assertFalse(p * (313 * (p - 1) + 1) * (353 * (p - 1) + 1))
Esempio n. 12
0
 def test_with_small_composites(self):
     self.assertFalse(isPrime(4))
     self.assertFalse(isPrime(6))
     self.assertFalse(isPrime(9))
     self.assertFalse(isPrime(10))
Esempio n. 13
0
 def test_with_small_primes(self):
     self.assertTrue(isPrime(3))
     self.assertTrue(isPrime(5))
     self.assertTrue(isPrime(7))
     self.assertTrue(isPrime(11))
Esempio n. 14
0
 def test_getRandomSafePrime(self):
     r = getRandomSafePrime(20)
     self.assertEqual(numBits(r), 20)
     self.assertTrue(isPrime(r))
     self.assertTrue(isPrime((r - 1) // 2))
Esempio n. 15
0
 def test_getRangomPrime(self):
     r = getRandomPrime(20)
     self.assertEqual(numBits(r), 20)
     self.assertTrue(isPrime(r))
    def test_with_hard_primes_to_test(self):

        # XXX Rabin-Miller fails to properly detect following composites
        with self.assertRaises(AssertionError):
            for i in range(100):
                # OEIS A014233
                self.assertFalse(isPrime(2047))
                self.assertFalse(isPrime(1373653))
                self.assertFalse(isPrime(25326001))
                self.assertFalse(isPrime(3215031751))
                self.assertFalse(isPrime(2152302898747))
                self.assertFalse(isPrime(3474749660383))
                self.assertFalse(isPrime(341550071728321))
                self.assertFalse(isPrime(341550071728321))
                self.assertFalse(isPrime(3825123056546413051))
                self.assertFalse(isPrime(3825123056546413051))
                self.assertFalse(isPrime(3825123056546413051))