- 155
- 0
- 约3.64千字
- 约 7页
- 2019-04-06 发布于天津
- 举报
编程实现RSA算法。包括:生成公钥(e, n)和私钥d,对明文m加密,对密文m解密。
注:实际应用中,512比特的n 已经不够安全,所以建议公司用1024比特的n,及其重要的场合用2048比特的 n。所以大家要选择大整数n。
#include iostream.h
#include math.h
#include stdio.h
typedef int Elemtype;
Elemtype p,q,e;
Elemtype fn;
Elemtype m,c;
int flag = 0;
typedef void (*Msghandler) (void);
struct MsgMap
{
char ch;
Msghandler handler;
};
/* 公钥 */
struct PU
{
Elemtype e;
Elemtype n;
} pu;
/* 私钥 */
struct PR
{
Elemtype d;
Elemtype n;
} pr;
/* 判定一个数是否为素数 */
bool test_prime(Elemtype m)
{
if (m = 1)
{
return false;
}
else if (m == 2)
{
return true;
}
else
{
for(int i=2; i=sqrt(m); i++)
{
原创力文档

文档评论(0)