📄 dll.cpp
字号:
//定义DLL_API,用于声明函数为DLL的导出函数
#define DLL_API _declspec(dllexport)
extern "C"
{
#include "miracl.h"
}
#include <stdio.h>
#include "dll.h"
//用于计算n=p*q
DLL_API big Gene_KeyN(big x,big y)
{
big n;
miracl *mip=mirsys(1000,0);
n=mirvar(0);
multiply(x,y,n);
return n;
}
//计算n的欧拉函数,Φ(n)=(p-1)(q-1);
DLL_API big Gene_Euler(big x,big y)
{
big temp,temp1,temp2,Euler;
miracl *mip=mirsys(1000,0);
temp1=mirvar(0);
temp2=mirvar(0);
Euler=mirvar(0);
temp=mirvar(1);
subtract(x,temp,temp1);
subtract(y,temp,temp2);
multiply(temp1,temp2,Euler);
return Euler;
mirkill(temp);
mirkill(temp1);
mirkill(temp2);
}
//产生公钥e,满足2<e<Φ(n)-1,其中GCD(e,Φ(n))=1;
DLL_API big Gene_PubKey(big x)
{
big e,temp,temp1;
miracl *mip=mirsys(1000,0);
e=mirvar(0);
temp=mirvar(1);
temp1=mirvar(0);
while(true)
{
bigrand(x,e);
egcd(x,e,temp1);
if(compare(temp1,temp)<=0)
break;
}
return e;
}
//产生私钥d,d=(e)-1 mod Φ(n)
DLL_API big Gene_PrivKey(big x,big y,big z)
{
big d,temp1,temp2,temp,Euler;
miracl *mip=mirsys(1000,0);
d=mirvar(0);
temp=mirvar(1);
temp1=mirvar(0);
temp2=mirvar(0);
Euler=mirvar(0);
subtract(x,temp,temp1);
subtract(y,temp,temp2);
multiply(temp1,temp2,Euler);
multi_inverse(1,&z,Euler,&d);
return d;
mirkill(temp);
mirkill(temp1);
mirkill(temp2);
}
//加密,生成密文c,c=(m)e mod n
DLL_API big EncMessage(big z,big x,big y)
{
big c;
miracl *mip=mirsys(1000,0);
c=mirvar(0);
powmod(z,x,y,c);
return c;
}
//加密,得到原始消息m,m=(c)d mod n
DLL_API big DecMessage(big x,big y,big z)
{
big m;
miracl *mip=mirsys(1000,0);
m=mirvar(0);
powmod(x,y,z,m);
return m;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -