File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 40
40
41
41
import math
42
42
import warnings
43
+ import random
43
44
from .util import bit_length
44
45
45
46
@@ -573,6 +574,7 @@ def is_prime(n):
573
574
574
575
t = 40
575
576
n_bits = 1 + bit_length (n )
577
+ assert 11 <= n_bits <= 16384
576
578
for k , tt in (
577
579
(100 , 27 ),
578
580
(150 , 18 ),
@@ -599,7 +601,7 @@ def is_prime(n):
599
601
s = s + 1
600
602
r = r // 2
601
603
for i in xrange (t ):
602
- a = smallprimes [ i ]
604
+ a = random . choice ( smallprimes )
603
605
y = pow (a , r , n )
604
606
if y != 1 and y != n - 1 :
605
607
j = 1
Original file line number Diff line number Diff line change @@ -305,6 +305,29 @@ def test_large_prime(self):
305
305
# nextPrime[2^2048]
306
306
assert is_prime (mpz (2 ) ** 2048 + 0x3D5 )
307
307
308
+ def test_pseudoprime_base_19 (self ):
309
+ assert not is_prime (1543267864443420616877677640751301 )
310
+
311
+ def test_pseudoprime_base_300 (self ):
312
+ # F. Arnault "Constructing Carmichael Numbers Which Are Strong
313
+ # Pseudoprimes to Several Bases". Journal of Symbolic
314
+ # Computation. 20 (2): 151-161. doi:10.1006/jsco.1995.1042.
315
+ # Section 4.4 Large Example (a pseudoprime to all bases up to
316
+ # 300)
317
+ p = int (
318
+ "29 674 495 668 685 510 550 154 174 642 905 332 730 "
319
+ "771 991 799 853 043 350 995 075 531 276 838 753 171 "
320
+ "770 199 594 238 596 428 121 188 033 664 754 218 345 "
321
+ "562 493 168 782 883" .replace (" " , "" )
322
+ )
323
+
324
+ assert is_prime (p )
325
+ for _ in range (10 ):
326
+ if not is_prime (p * (313 * (p - 1 ) + 1 ) * (353 * (p - 1 ) + 1 )):
327
+ break
328
+ else :
329
+ assert False , "composite not detected"
330
+
308
331
309
332
class TestNumbertheory (unittest .TestCase ):
310
333
def test_gcd (self ):
You can’t perform that action at this time.
0 commit comments