'''
RSA Baby Payload
req.
egcd(a,b) -> s, t
modInv(a, b) -> inv
'''
def gcd(a, b):
if b > a:
tmp = a
a = b
b = tmp
while b != 0:
tmp = b
b = a%b
a = tmp
return a
# egcd
def modInv(b, a):
if a > b:
r = [a, b]
s = [0, 1]
else:
r = [b, a]
s = [1, 0]
while r[1] != 0:
q = r[0] // r[1]
r.append(r[0] - q * r[1])
del r[0]
s.append(s[0] - q * s[1])
del s[0]
if s[0] < 0:
s[0] += a
return s[0]
N =
e = 65537
g =
enc_flag =
p = gcd(pow(2, (e*g) + (0xdeadbeaf-1), N)-1, N)
q = N//p
piN = (p-1)*(q-1)
d = modInv(e, piN)
print("Priv : " + str(d))
flag = pow(enc_flag, d, N)
print(hex(flag)[2:-1].decode('hex'))