56.实验吧——rsarsa

http://www.shiyanbar.com/ctf/1979

image.png

image.png

根据题干,已知pq,可求出N=pq,(N,e)是公钥,(N,d)是私钥
c是密文,
已知公钥、私钥、密文,求明文?
写出解密代码rsarsa.py(在kali系统下运行,因为我之前已经安装了gmpy2模块)

import gmpy2
p =  9648423029010515676590551740010426534945737639235739800643989352039852507298491399561035009163427050370107570733633350911691280297777160200625281665378483
q = 11874843837980297032092405848653656852760910154543380907650040190704283358909208578251063047732443992230647903887510065547947313543299303261986053486569407
e =  65537
c = 83208298995174604174773590298203639360540024871256126892889661345742403314929861939100492666605647316646576486526217457006376842280869728581726746401583705899941768214138742259689334840735633553053887641847651173776251820293087212885670180367406807406765923638973161375817392737747832762751690104423869019034
s = (p- 1) * (q - 1)
d =long(gmpy2.invert(e, s))
n = p *q
print pow(c, d, n)
image.png

得到flag:5577446633554466577768879988


二、另一个rsa解密题——求d
http://www.shiyanbar.com/ctf/1828

image.png

image.png
s=(p-1)*(q-1)
d=gmpy2.invert(e,s)

得到flag就是d的值
————————————————————————————————————————————————————
三、已知n、e和密文,求p、q,继而求明文
http://www.shiyanbar.com/ctf/1918

image.png

由题目知道n,通过在线因式分解得到p和q(http://factordb.com/index.php)
image.png

故,写好解密代码,在kali系统运行(需提前安装gmpy2和sys模块)

import gmpy2
import sys
p=18443
q=49891
n=920139713
s=(p-1)*(q-1)
e=19
d=gmpy2.invert(e,s)
B = [
     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, 
     ]
for b in B:
    sys.stdout.write(chr(pow(b,d,n)))   #这里用printf会换行,所以用sys.stdout.write
image.png

flag{13212je2ue28fy71w8u87y31r78eu1e2}

你可能感兴趣的:(56.实验吧——rsarsa)