def _genRhoBGamma(cls):
     while True:
         rho = cmod.randomPrime(LARGE_PUBLIC_RHO)
         b = cmod.randomBits(LARGE_PUBLIC_B)
         Gamma = b * rho + 1
         if cmod.isPrime(Gamma) and (rho % b != 0):
             return rho, b, Gamma
Пример #2
0
def get_prime_in_range(start, end):
    n = 0
    maxIter = 100000
    while n < maxIter:
        r = randint(start, end)
        if cmod.isPrime(r):
            logging.debug("Found prime in {} iterations".format(n))
            return r
        n += 1
    raise Exception("Cannot find prime in {} iterations".format(maxIter))
Пример #3
0
 def _genPrime(cls):
     # Generate 2 large primes `p_prime` and `q_prime` and use them
     # to generate another 2 primes `p` and `q` of 1024 bits
     prime = cmod.randomPrime(LARGE_PRIME)
     i = 0
     while not cmod.isPrime(2 * prime + 1):
         prime = cmod.randomPrime(LARGE_PRIME)
         i += 1
     print("In {} iterations, found prime {}".format(i, prime))
     return prime
Пример #4
0
def genPrime():
    """
    Generate 2 large primes `p_prime` and `q_prime` and use them
    to generate another 2 primes `p` and `q` of 1024 bits
    """
    prime = cmod.randomPrime(LARGE_PRIME)
    i = 0
    while not cmod.isPrime(2 * prime + 1):
        prime = cmod.randomPrime(LARGE_PRIME)
        i += 1
    return prime