rsarsa: Math is cool! Use the RSA algorithm to decode the secret m

http://www.shiyanbar.com/ctf/1979
rsarsa:
Math is cool! Use the RSA algorithm to decode the secret message, c, p, q, 
and e are parameters for the RSA algorithm.
解题链接: http://ctf5.shiyanbar.com/crypto/rsarsa/rsa.txt


解:
之前做过rsa,在我的博客中也分享鄙人的解题过程,http://blog.csdn.net/dongyanwen6036/article/details/76582310
如果你不了解rsa,那么你先应该去知道原理(去上面的链接)。


得出明文:
5577446633554466577768879988
这个也是最后的flag.

实现的代码和截图如下:

#from __future__ import division
#---------------------------------------------------------------
#分解大整数
import math

#-------------------------------------
# 求欧拉函数f(n)
def getEuler(prime1, prime2):
    return (prime1-1)*(prime2-1)
#---------------------------------------------------------------------------------------
# 19d - 920071380k= 1
# 求私钥d
def getDkey(e, Eulervalue):#可以辗转相除法
	k = 1
	while True:
		if (((Eulervalue * k) + 1) % e) == 0:
			(d,m)=divmod(Eulervalue * k + 1,e)
			return d#避免科学计数法最后转int失去精度
		k += 1
#------------------------------------------------------
#求明文
def Ming(c,d,n):
	return pow(c,d,n)
#---------------------------------------------------------------------------------------
if __name__=='__main__':
	p=9648423029010515676590551740010426534945737639235739800643989352039852507298491399561035009163427050370107570733633350911691280297777160200625281665378483
	q=11874843837980297032092405848653656852760910154543380907650040190704283358909208578251063047732443992230647903887510065547947313543299303261986053486569407
	d=getDkey(65537,getEuler(p,q))
	print('私钥为: %d'%d)
	c=83208298995174604174773590298203639360540024871256126892889661345742403314929861939100492666605647316646576486526217457006376842280869728581726746401583705899941768214138742259689334840735633553053887641847651173776251820293087212885670180367406807406765923638973161375817392737747832762751690104423869019034
	n=p*q
	print('明文如下: ')
	print(Ming(c,d,n))
	
	






	


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值