from Crypto.Util.number import * import binascii flag = open('flag.txt','rb').read() p = getPrime(1024) q = getPrime(1024) n = p*q e = 2**16+1 pt = int(binascii.hexlify(flag).decode(),16) print(p>>512) print(q%(2**512)) print(n, e) print(pow(pt,e,n))
と を上下半分ずつ与えられている
with open("output.txt") as f: ph = int(f.readline().strip()) ql = int(f.readline().strip()) n = int(f.readline().strip().split(" ")[0]) c = int(f.readline().strip()) qhigh = n // (ph << 512) for diff in range(-10000, 10000): qh = (qhigh >> 512) + diff q = (qh << 512) | ql if n % q == 0: break p = n // q d = pow(65537, -1, (p-1)*(q-1)) m = pow(c, d, n) print(bytes.fromhex(hex(m)[2:]))