Skip to content

Instantly share code, notes, and snippets.

@dendisuhubdy
Created October 20, 2015 02:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dendisuhubdy/a821728833b05bc6ea48 to your computer and use it in GitHub Desktop.
Save dendisuhubdy/a821728833b05bc6ea48 to your computer and use it in GitHub Desktop.
Cracking the RSA cyprtosystem time
import gmpy, time, random, math
def genprime(bits):
p=1
while(gmpy.is_prime(p)==0):
p = random.randrange(math.pow(2,bits-1),math.pow(2,bits))
return p
BITS=20
found=False
p=genprime(BITS)
q=genprime(BITS)
n=p*q
cnt=2
s_time=time.time()
while not found:
found=(n%cnt==0)
cnt+=1
e_time=time.time()-s_time
if found:
print "%d can be devided by %d"%(n, cnt-1)
print "It took %d ms "%(cnt-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment