关于RSA的解密,要了解RSA的算法RSA算法 - 简书RSA是目前使用最广泛的公钥密码体制之一。它是1977年由罗纳德·李维斯特(Ron Rivest)、阿迪·萨莫尔(Adi Shamir)和伦纳德·阿德曼(Leonard Ad...https://www.jianshu.com/p/ff2b538a77e2
解出RSA需要了解以下关系:
c = 明文
d = pow(e,phi) = 私钥
n = q*p = 公钥
phi = (p-1)*(q-1) = n的欧拉函数 #通过phi可以求私钥d
m = pow(c,d,n) =密 文
1.首先题目给出e,n,c。n又是q*p,所以我们就可以通过fayu解出p和q
fayu功能是自动分解整数因式,用法如下
yafu-x64.exe "factor(需要分解的数)"
求得p和q
q = 274539690398523616505159415195049044439
p = 322368694010594584041053487661458382819
代码如下
import gmpy2
import libnum
q = 274539690398523616505159415195049044439
p = 322368694010594584041053487661458382819
n = 88503001447845031603457048661635807319447136634748350130947825183012205093541
c = 40876621398366534035989065383910105526025410999058860023908252093679681817257
e = 65537
phi = (q-1)*(p-1) #phi为n的欧拉函数
print(phi)
d = int(gmpy2.invert(e,phi)) #d是私钥
print(d)
flag = pow(c,d,n)
print(libnum.n2s(flag))
HSCTF{@Zh3n_Ba1_G3i!@}