Skip to content

Instantly share code, notes, and snippets.

@kostyll
Forked from dendisuhubdy/rsacrack.py
Created October 28, 2015 17:25
Show Gist options
  • Save kostyll/5995278c9df5eb102d31 to your computer and use it in GitHub Desktop.
Save kostyll/5995278c9df5eb102d31 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