hint_str = lines[0].split('=')[1].strip() exps = [] for term in hint_str.split('+'): term = term.strip() if not term: continue if term == '1': exps.append(0) elif term == 'X': exps.append(1) elif term.startswith('X^'): exps.append(int(term[2:]))
hint_poly = sum(x**e for e in exps)
将形如”1 + X + X^2 + … + X^r”的字符串转换为多项式对象。
步骤6:循环平移与解密
对重构得到的B(x)进行所有可能的循环平移:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
B_S = S(B) nonce = b"suanp01y"
for k in range(r): h0_candidate = B_S * (X**k) # 循环平移 key = md5(str(h0_candidate).encode()).digest()
try: cipher = AES.new(key, AES.MODE_CTR, nonce=nonce) flag = cipher.decrypt(ct) if flag.startswith(b"RCTF{"): print("Success!") print(flag) return except: continue
for term in hint_str.split('+'): term = term.strip() if not term: continue if term == '1': exps.append(0) elif term == 'X': exps.append(1) elif term.startswith('X^'): exps.append(int(term[2:]))
hint_poly = sum(x**e for e in exps) ct = bytes.fromhex(lines[1])
A, B = rational_reconstruction(hint_poly)
if B is None: print("Fail") return
B_S = S(B) nonce = b"suanp01y"
for k in range(r): h0_candidate = B_S * (X**k) key = md5(str(h0_candidate).encode()).digest()
try: cipher = AES.new(key, AES.MODE_CTR, nonce=nonce) flag = cipher.decrypt(ct) if flag.startswith(b"RCTF{"): print("Success!") print(flag) return except: continue
💬 评论与讨论
分享你的想法和见解