Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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:
# 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:
q = n/p
thetans = (p-1)*(q-1)
d = libnum.invmod(e,thetans)
m = pow(c,d,n)
out += libnum.n2s(m)
print out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.