BUU刷题日记20221020
RSA1
给定dp、dq类型
dp ≡ d mod (p-1)
dq ≡ d mod (q-1)
m ≡ cd mod n
m = cd + k * n
m = cd +k * p * q
对上式两端同时对p、q分别取余,得:(中国剩余定理)
m1 ≡ cd mod p
m2 ≡ cd mod q
同理,可得到 cd = m1 +k * p
代入到 m2 ≡ cd mod q 中:
m2 ≡ (m1 + k * p)mod q ,两端减去m1得
m2 - m1 ≡ k * p mod q ,两端乘p的逆元得
(m2 - m1)p-1 ≡ k mod q
将k代入到 cd = m1 +k * p 中得:
cd = m1 + ((m2 - m1)p-1 mod q) * p
m=cd mod n
得到
m ≡ (((m2 - m1) * p-1 mod q) * p + m1) mod n
接下来就是求解m1,m2
m1 ≡ cdp+k(p-1) mod p
m2 ≡ cdq+k(q-1) mod q
根据费马小定理
若p是素数,则a(p-1) ≡ 1 mod p
因此 m1 ≡ cdp mod p,m2 ≡ cdq mod q
最终可求得m
exp
1 |
|
RSAROLL
1 |
|
给了一个data.txt文件,打开盲猜一下第一行是n,e,后面是c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17import gmpy2
from Crypto.Util.number import long_to_bytes
n = 920139713
e = 19
p=18443
q=49891
phi =(p-1)*(q-1)
d=gmpy2.invert(e,phi)
c=[704796792,752211152,274704164,18414022,368270835,483295235,263072905,459788476,483295235,459788476,663551792,475206804,459788476,428313374,475206804,459788476,425392137,704796792,458265677,341524652,483295235,534149509,425392137,428313374,425392137,341524652,458265677,263072905,483295235,828509797,341524652,425392137,475206804,428313374,483295235,475206804,459788476,306220148,
]
m=[]
flag=b''
for i in range (len(c)):
m.append(pow(c[i],d,n))
flag+=long_to_bytes(m[i])
print(flag)
#flag{13212je2ue28fy71w8u87y31r78eu1e2}