Skip to content

Commit f520014

Browse files
adamantikesybrenstuvel
authored andcommitted
Trivial fix on primality testing
1 parent 38a7255 commit f520014

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

rsa/prime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def miller_rabin_primality_testing(n, k):
9696
# Test k witnesses.
9797
for _ in range(k):
9898
# Generate random integer a, where 2 <= a <= (n - 2)
99-
a = rsa.randnum.randint(n - 4) + 2
99+
a = rsa.randnum.randint(n - 3) + 1
100100

101101
x = pow(a, d, n)
102102
if x == 1 or x == n - 1:

tests/test_prime.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ def fake_randint(maxvalue):
5959
rsa.randnum.randint = fake_randint
6060
try:
6161
# 'n is composite'
62-
randints.append(2630484831) # causes the 'n is composite' case with n=3784949785
62+
randints.append(2630484832) # causes the 'n is composite' case with n=3784949785
6363
self.assertEqual(False, rsa.prime.miller_rabin_primality_testing(2787998641, 7))
6464
self.assertEqual([], randints)
6565

6666
# 'Exit inner loop and continue with next witness'
6767
randints.extend([
68-
2119139097, # causes 'Exit inner loop and continue with next witness'
68+
2119139098, # causes 'Exit inner loop and continue with next witness'
6969
# the next witnesses for the above case:
70-
3051067715, 3603501762, 3230895846, 3687808132, 3760099986, 4026931494, 3022471881,
70+
3051067716, 3603501763, 3230895847, 3687808133, 3760099987, 4026931495, 3022471882,
7171
])
7272
self.assertEqual(True, rsa.prime.miller_rabin_primality_testing(2211417913,
7373
len(randints)))

0 commit comments

Comments
 (0)