Skip to content

Instantly share code, notes, and snippets.

@faidamine
Last active May 12, 2017 03:23
Show Gist options
  • Save faidamine/bcd65d62a0603206dc6467af2ec4bada to your computer and use it in GitHub Desktop.
Save faidamine/bcd65d62a0603206dc6467af2ec4bada to your computer and use it in GitHub Desktop.
#usr/bin/python
#Faid Mohammed Amine
#Fb : piratuer
#MCSC 2017 RSA 100pts
import gmpy
import binascii
def wood_func(n):
return n*pow(2,n)-1
def bytes_from_file(filename, chunksize=8192):
with open(filename, "rb") as f:
while True:
chunk = f.read(chunksize)
if chunk:
for b in chunk:
yield b
else:
break
def main(n):
i = 100
while(i<500):
w = wood_func(i)
p = n / w
if((p * w) == n):
q = w
print "Found " + str(q)
i = 500
i += 1
phi = (p-1)* (q-1)
d = gmpy.invert(e,phi)
c = ""
for bt in bytes_from_file('encrypted_lladoow'):
c += binascii.hexlify(bt)
c = int(c,16)
m = hex(pow(c,d,n))[2:]
flag = m.decode('hex')
return flag
if __name__ == "__main__":
n = int(open("N").read().encode('hex'),16)
e = int(open("E").read().encode('hex'),16)
print main(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment