ciphers.deterministic_miller_rabin

Created by Nathan Damon, @bizzfitch on github >>> test_miller_rabin()

Functions

miller_rabin(→ bool)

Deterministic Miller-Rabin algorithm for primes ~< 3.32e24.

test_miller_rabin(→ None)

Testing a nontrivial (ends in 1, 3, 7, 9) composite

Module Contents

ciphers.deterministic_miller_rabin.miller_rabin(n: int, allow_probable: bool = False) bool

Deterministic Miller-Rabin algorithm for primes ~< 3.32e24.

Uses numerical analysis results to return whether or not the passed number is prime. If the passed number is above the upper limit, and allow_probable is True, then a return value of True indicates that n is probably prime. This test does not allow False negatives- a return value of False is ALWAYS composite.

Parameters

nint

The integer to be tested. Since we usually care if a number is prime, n < 2 returns False instead of raising a ValueError.

allow_probable: bool, default False

Whether or not to test n above the upper bound of the deterministic test.

Raises

ValueError

Reference

https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test

ciphers.deterministic_miller_rabin.test_miller_rabin() None

Testing a nontrivial (ends in 1, 3, 7, 9) composite and a prime in each range.