📄 module.h
字号:
#ifndef Module_h
#define Module_h
#define Primefile "P(3,40000].txt"
#define Mingfile "ming.txt"
#define Cipherfile "cipher.txt"
#define Decipherfile "decipher.txt"
void Module1();//分配模块;
void Module2();
void Module3();
void Module4();
void Module1(){
long bogusprime=0;
long T=0;
long i,j;
double max=0;
double temp;
long n=1;
long b=20,c=20;
cout<<"Module1 的功能:"<<endl;
cout<<"输出欧拉伪素数的个数与Zn*的个数之比的最大值max(|Bogusprime|/|Zn*|) for n"<<endl<<endl;
cout<<"请输入决定n范围的两个参数b,c,使得n=b*c<=40000"<<endl;
cout<<"b=";
cin>>b;
cout<<"c=";
cin>>c;
cout<<"n in [3,"<<b*c<<"]"<<endl;
for(i=3;i<b;i=i+2)//00
for(j=i+2;j<c;j=j+2)//两个奇数相乘结果为奇整数;
{
Verify(i*j,bogusprime,T);
temp=double(bogusprime)/T;
if(temp>max)
{
max=temp;
n=i*j;
}
}
//cout<<"("<<bogusprime<<"/"<<T<<")"<<" for "<<i*j<<endl;
cout<<"max(|Bogusprime|/|Zn*|)="<<max<<" for n="<<n<<endl;
}
void Module2(){
long m=1,N=1021;
long m1=2,m2=5,m3=10;
cout<<"请输入N(待测试的n属于N~2N,N<=20000):"<<endl;//
cout<<"N=";
cin>>N;
cout<<"m;Pr[b|a];1/pow(2,m)"<<endl;
Pr_ba(m,N);
while(m<=10){
Pr_ba(m*m1,N);
Pr_ba(m*m2,N);
m=m*m3;
Pr_ba(m,N);
}
cout<<endl;
m=1;
cout<<"m;Pr[a|b];(ln(n)-2)/(ln(n)-2+pow(2,m+1))"<<endl;
Pr_ab(m,N);
while(m<=10){
Pr_ab(m*m1,N);
Pr_ab(m*m2,N);
m=m*m3;
Pr_ab(m,N);
}
}
void Module3(){
Long l=2,h;
Long m=100;
cout<<"Module3温馨提醒你,由于定义了超长整数类class Long,所以十进制数范围可超过十位"<<endl;
cout<<"请输入素数生成器的参数:"<<endl;
cout<<"输入素数的下界down=";
cin>>l;
cout<<"输入素数的上界up=";
cin>>h;
cout<<"输入询问素数检验器的次数m=";
cin>>m;
Prime_Generator(l,h,m);
long a=10;//这里默认询问素数检验器次数为10;
int s=Verifyfile(Primefile,a);//检验网上下载的素数发生器,只有检验到不是素数才有输出;
if(s)
cout<<endl<<Primefile<<"'s numbers are all primes!"<<endl;
}
void Module4(){
RSA<Long> r;
Long down="1234567890123456789000",up="1234567890123456789099";
Long a,b,n,p,q;
Long m=10;
Prime_Double(down,up,m,p,q);
cout<<"素因子p="<<p<<endl;
cout<<"素因子q="<<q<<endl;
n=p*q;
cout<<"n=p*q="<<n<<endl;
srand((unsigned)time(NULL));
b=rand();
while((a=Inverse(b,(p-1)*(q-1)))==0)b=rand();
cout<<"加密指数b="<<b<<endl;
cout<<"解密指数a="<<a<<endl;
r.EnInitialKey(b,n);
r.Encipher(Mingfile,Cipherfile);
r.DeInitialKey(a,n);
r.Decipher(Cipherfile,Decipherfile);
cout<<endl;
r.CRTInitialKey(p,q,a,n);
r.CRT_Optimized(Cipherfile,Decipherfile);
cout<<endl;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -