EGCryptoSystem.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:helios-server-mixnet 作者: RunasSudo 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号