Created
April 13, 2016 13:50
-
-
Save AndyNovo/05758e876d5edec3dda2a44668f0d3af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def safe_prime(bits): | |
found_safe_prime = False | |
ohshit = 0 | |
while (not found_safe_prime and ohshit < 1000000): | |
ohshit += 1 | |
q = 2*randint(2**(bits-1), 2**(bits))-1 | |
if power_mod(2,2*q, 2*q + 1) != 1: | |
continue | |
if not q.is_prime(False): | |
continue | |
found_safe_prime = True | |
if ohshit >= 1000000: | |
return -1 | |
return 2*q+1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment