BUUCTF-rsarsa1

简介: BUUCTF-rsarsa1

1.题目需要下载一个压缩包,解压之后得到题目描述如下

Math is cool! Use the RSA algorithm to decode the secret message, c, p, q, and e are parameters for the RSA algorithm.
 
 
p =  9648423029010515676590551740010426534945737639235739800643989352039852507298491399561035009163427050370107570733633350911691280297777160200625281665378483
q =  11874843837980297032092405848653656852760910154543380907650040190704283358909208578251063047732443992230647903887510065547947313543299303261986053486569407
e =  65537
c =  83208298995174604174773590298203639360540024871256126892889661345742403314929861939100492666605647316646576486526217457006376842280869728581726746401583705899941768214138742259689334840735633553053887641847651173776251820293087212885670180367406807406765923638973161375817392737747832762751690104423869019034
 
Use RSA to find the secret message

2.一开始我想到了用rsa算法工具,但是发现有些参数在工具中用不到,因此只能放弃工具,接下来就可以利用代码编写来实现

3.在pycharm中运行如下代码即可拿到flag

from gmpy2 import invert
 
p = 9648423029010515676590551740010426534945737639235739800643989352039852507298491399561035009163427050370107570733633350911691280297777160200625281665378483
q = 11874843837980297032092405848653656852760910154543380907650040190704283358909208578251063047732443992230647903887510065547947313543299303261986053486569407
e = 65537
c = 83208298995174604174773590298203639360540024871256126892889661345742403314929861939100492666605647316646576486526217457006376842280869728581726746401583705899941768214138742259689334840735633553053887641847651173776251820293087212885670180367406807406765923638973161375817392737747832762751690104423869019034
n = p * q
y = (p - 1) *(q - 1)
d = invert(e, y)
flag = pow(c, d, n)
print(flag)

4.代码的解释如下

from gmpy2 import invert:这一行导入了 gmpy2 模块中的 invert 函数,用于计算模反函数。

e是指数的意思

c是密文

pow(c,d,n)是c和d的乘积模上n

d = invert(e, y):这一行使用 invert 函数计算 e 在模 y 下的逆元,即私钥中的指数。

5.最终flag

flag{5577446633554466577768879988}
相关文章
|
6月前
BUUCTF easyre 1
BUUCTF easyre 1
59 0
|
6月前
|
数据安全/隐私保护
BUUCTF 九连环 1
BUUCTF 九连环 1
174 0
|
6月前
|
网络协议 数据安全/隐私保护
BUUCTF 神秘龙卷风 1
BUUCTF 神秘龙卷风 1
204 0
|
6月前
BUUCTF 来首歌吧 1
BUUCTF 来首歌吧 1
361 0
|
6月前
|
SQL 数据库
BUUCTF sqltest 1
BUUCTF sqltest 1
316 0
|
6月前
|
数据格式 Python
BUUCTF 梅花香之苦寒来 1
BUUCTF 梅花香之苦寒来 1
157 1
|
6月前
|
流计算
BUUCTF [MRCTF2020]ezmisc 1
BUUCTF [MRCTF2020]ezmisc 1
121 0
|
6月前
BUUCTF [HBNIS2018]低个头 1
BUUCTF [HBNIS2018]低个头 1
57 0
|
6月前
BUUCTF 你竟然赶我走 1
BUUCTF 你竟然赶我走 1
111 0
|
6月前
|
数据安全/隐私保护
BUUCTF ningen 1
BUUCTF ningen 1
85 0