RSA非对称加密

先上RSA加密算法的一些简介(截图自轩辕老师的课件):




嗯……RSA就是这么一回事,于是有了如下题目:

1、In an RSA system, the public key of a given user is e=31, n=3599. What is the private key of this user?

2、In a public key system using RSA, you intercept the ciphertext C=10 sent to a user whose publick key is e=5, n=35. What is the plaintext M?

解析:RSA解密公式 M = C^d mod n中,C 和 n都是已知的,要求的是d,那么d怎么来的呢,如下公式:

(a)n = p*q; 

 (b)φ(n)表示欧拉函数:所有比n小同时又跟n互质的正整数的个数

(c) e = d^(-1) mod φ(n)   -->   d = e^(-1) mod φ(n), 注意这里的-1次方不是真的-1次方,而是表示的是乘法逆,乘法逆是什么鬼?详细的我笔记有。简单的说乘法逆就是我拿 d 跟 e 相乘,然后mod φ(n) 得到的是1,那 d 就是 e 关于φ(n)的乘法逆。

然后就可以解答了:

先求 n 和 φ(n),然后求d,求出了d再根据解密的公式就可以求出明文M了。

只是这里的求d用到一个乘法逆的公式,有些难求,所以我写了一小段C语言代码如下,不过我想是不是有更快的方法根本不用怎么计算更不用写程序就能求出乘法逆的?



原文地址:https://www.cnblogs.com/lvlang/p/10586482.html