Skip to content

Instantly share code, notes, and snippets.

@CreateRemoteThread
Last active May 31, 2016 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CreateRemoteThread/b03038f3e199bd85459229a33ff125eb to your computer and use it in GitHub Desktop.
Save CreateRemoteThread/b03038f3e199bd85459229a33ff125eb to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import libnum
f = open("in.txt","r")
data = f.readlines()
data_clustered = [(int(data[x].rstrip().lstrip("n = ")),int(data[x+1].rstrip().lstrip("e = ")),int(data[x+2].rstrip().lstrip("c = "))) for x in range(0,len(data),3)]
pubkeys = []
for (n,e,c) in data_clustered:
pubkeys.append(n)
# x = libnum.factorize(int(n))
# print x
out = ""
print "starting factorisation with %d keys" % len(pubkeys)
for (n,e,c) in data_clustered:
for n2 in pubkeys:
if n != n2:
p = libnum.gcd(n,n2)
if p == 0 or p == 1:
continue
q = n/p
thetans = (p-1)*(q-1)
d = libnum.invmod(e,thetans)
m = pow(c,d,n)
out += libnum.n2s(m)
break
f.close()
print out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment