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}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值