def _is_safe_prime(p, probability=params.FALSE_PRIME_PROBABILITY):
"""
Test if the number p is a safe prime.
A safe prime is one of the form p = 2q + 1, where q is also a prime.
Arguments:
p::long -- Any integer.
probability::int -- The desired maximum probability that p
or q may be composite numbers and still be
declared prime by our (probabilistic)
primality test. (Actual probability is
lower, this is just a maximum provable bound)
Returns:
True if p is a safe prime
False otherwise
"""
# Get q (p must be odd)
if(p % 2 == 0):
return False
q = (p - 1)/2
# q first to shortcut the most common False case
return (number.isPrime(q, false_positive_prob=probability)
and
number.isPrime(p, false_positive_prob=probability))
评论列表
文章目录