Skip to content

Instantly share code, notes, and snippets.

@AndyNovo
Created April 13, 2016 13:50
Show Gist options
  • Save AndyNovo/05758e876d5edec3dda2a44668f0d3af to your computer and use it in GitHub Desktop.
Save AndyNovo/05758e876d5edec3dda2a44668f0d3af to your computer and use it in GitHub Desktop.
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