def isprime(num, no_of_passes=20): r = get_random() for repeat in xrange(no_of_passes): a = 0 while a == 0: a = r.randrange(num) if not rabin_miller_pass(a, num): return False return True
def generate_keys(bitlength) : r = get_random() p, q = rsa_primes(bitlength) n = p * q phin = (p - 1) * (q - 1) while True : e = r.randint(1, phin) while e == 1 or euclidean(e, phin) != 1 : e = r.randint(1, phin) d = extended_euclidean(phin, e)[3] d = (d + phin) % phin return ((e, n),(d,n),(p,q))
def generate_prime_bits(bit_length): sieve = sieve_of_atkins(65000) testers = list() while len(testers) == 0: testers = [ get_random().getrandbits(bit_length) | 1 for x in xrange(1000) ] for x in sieve: testers = filter(lambda y: y % x != 0, testers) testers = filter(isprime, testers) if len(testers) > 0: return testers[0]
def test_getting_random_is_same_object(self): rand1 = prng.get_random() rand2 = prng.get_random() self.assertTrue(rand1 is rand2)
def generate_prime_bits_simp(bit_length): p = get_random().getrandbits(bit_length) | 1 while not isprime(p): p = get_random().getrandbits(bit_length) | 1 return p