WaniCTF 2021 Spring | Can't restore the flag

#wanictf2021spring

from Crypto.Util.number import bytes_to_long

with open("flag.txt", "rb") as f:
    flag = f.read()
flag = bytes_to_long(flag)

assert flag <= 10 ** 103

upper_bound = 300
while True:
    try:
        mod = int(input("Mod > "))
        if mod > upper_bound:
            print("Don't cheat 🤪")
            continue

        result = flag % mod
        print(result)
    except Exception:
        print("Bye 👋")
        break

どう見てもCRTやるだけ。ところで modが 負の場合を考えていないので -9999999999 とかを与えても解ける 作問するときに気をつけること

from ptrlib import Socket, crt
import gmpy2

sock = Socket("crt.cry.wanictf.org", 50000)

pairs = []
mod = 2

while mod <= 300:
    sock.sendlineafter("Mod > ", str(mod))
    x = int(sock.recvline())
    pairs.append((x, mod))
    mod = gmpy2.next_prime(mod)

m, n = crt(pairs)

print(bytes.fromhex(hex(m)[2:]))