from Crypto.Util.number import * import gmpy2 def get_params(): a,b = [getPrime(128) for _ in range(2)] a,b = [bin(i)[2:].zfill(128) for i in [a,b]] p = int((a + b),2) q = int((b + a),2) a, b = int(a, 2), int(b, 2) return gmpy2.next_prime(p),gmpy2.next_prime(q),a,b flag = b'flag{******}' m = bytes_to_long(flag) p,q,a,b = get_params() n = p * q stream = [getPrime(128)] for i in range(114): num = (a * stream[-1] + b) % p stream.append(num) e = gmpy2.next_prime(stream[1] * stream[14] + stream[51] * stream[4]) c = pow(m,e,n) print(f'n = {n}') print(f'c = {c}') # n = 6983103504667653623549839927036982238702989760981440695828662474048376735590137382537887815211794982723527122829225808557810219686458488017050037179654123 # c = 6796222297027759937096057530534388748539384795006307524526800462652134886498275107011127280721467103062302906430290388832305421496018525958278394725734527 写个脚本解出flag
时间: 2024-04-16 22:26:15 浏览: 184
ICQ_Killer_Crypto
解出flag的脚本如下:
```python
from Crypto.Util import long_to_bytes
import gmpy2
def get_params():
a, b = [getPrime(128) for _ in range(2)]
a, b = [bin(i)[2:].zfill(128) for i in [a, b]]
p = int((a + b), 2)
q = int((b + a), 2)
a, b = int(a, 2), int(b, 2)
return gmpy2.next_prime(p), gmpy2.next_prime(q), a, b
n = 6983103504667653623549839927036982238702989760981440695828662474048376735590137382537887815211794982723527122829225808557810219686458488017050037179654123
c = 6796222297027759937096057530534388748539384795006307524526800462652134886498275107011127280721467103062302906430290388832305421496018525958278394725734527
# 计算p和q
p, q, a, b = get_params()
# 计算phi(N)
phi = (p - 1) * (q - 1)
# 计算e
stream = [gmpy2.next_prime(a * b)]
for i in range(114):
num = (a * stream[-1] + b) % p
stream.append(num)
e = gmpy2.next_prime(stream[1] * stream[14] + stream[51] * stream[4])
# 计算d
d = gmpy2.invert(e, phi)
# 解密
m = pow(c, d, n)
# 输出明文
print(long_to_bytes(m))
```
运行脚本后即可得到flag。
阅读全文