RSA #include using namespace std; long gcd(long a, long b) { if(b>a) //a 中存放较大的数,b 中存放较小的数 { int temp; temp=a; a=b; b=temp; } long n; while((n=a%b)!=0) { a=b; b=n; } return b; } //--------------------------------------- long cheng_niyuan(long a, long b) { for(long i=1; (i*a)%b!=1; i++); return i; } //--------------------------------------- int mi_mo(int a, int b, int n) { int K[100]; int top=-1; while(b) { top++; K[top]=(b%2); b/=2; } int c=0, f=1; for(; top>=0; top--) { c=2*c; f=(f*f)%n; if(K[top]==1) { c+=1; f=(f*a)%n; } } return f; } //--------------------------------------- int main() { int p=5,q=11; cout<<"p="<
>M; C=mi_mo(M, e, n); cout<<"对应的密文为:"<>C; M=mi_mo(C, d, n); cout<<"对应的明文为:"<