Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test for Mersenne primes #60

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/test_prime.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ def fake_randint(maxvalue):
finally:
rsa.randnum.randint = orig_randint

def test_mersenne_primes(self):
"""Tests first known Mersenne primes.

Mersenne primes are prime numbers that can be written in the form
`Mn = 2**n - 1` for some integer `n`. For the list of known Mersenne
primes, see:
https://en.wikipedia.org/wiki/Mersenne_prime#List_of_known_Mersenne_primes
"""

# List of 20 first known Mersenne exponents.
known_mersenne_exponents = [
2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279,
2203, 2281, 3217, 4253, 4423,
]

# Test Mersenne primes.
for exp in known_mersenne_exponents:
self.assertTrue(rsa.prime.is_prime(2**exp - 1))

def test_get_primality_testing_rounds(self):
"""Test round calculation for primality testing."""

Expand Down