defgaussian_reduce(v1, v2): whileTrue: ifsum(x * x for x in v2) < sum(x * x for x in v1): v1, v2 = v2, v1 quotient = round( sum(a * b for a, b inzip(v1, v2)) / sum(a * a for a in v1) ) if quotient == 0: return v1, v2 v2 = [b - quotient * a for a, b inzip(v1, v2)]
q, h = public_key encrypted = ciphertext (f, g), _ = gaussian_reduce((1, h), (0, q))
a = f * encrypted % q message = (a * inverse(f, g)) % g print(message)
原始材料没有保留公钥、密文和最终输出,因此只记录攻击原理。
Cross wires
题目分析
题目使用同一个 N 和自己的私钥 d,先后使用 5 个朋友的公钥指数对 flag 进行 RSA 加密。已知 d 可以先分解 N,再从最后一个朋友开始逆向解密。
from Crypto.Util.number import long_to_bytes from sympy import nextprime
N, d = private_key g = 2 t = 65537 * d - 1
whileTrue: while t % 2 == 0: candidate = gcd(pow(g, t // 2, N) - 1, N) if1 < candidate < N: p = candidate q = N // p break t //= 2 if"p"inlocals(): break g = nextprime(g) t = 65537 * d - 1
💬 评论与讨论
分享你的想法和见解