rsa1.cpp 428 B

12345678910111213141516171819
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int encrypt(int m,int e,int n){int c=1;for(int i=0;i<e;i++){c=(c*m)%n;}return c;}
  4. char m[1024];
  5. int c[1024];
  6. int i,k,e,n;
  7. int main(){
  8. cout<<"n:";
  9. cin>>n;
  10. cout<<"e:";
  11. cin>>e;
  12. cout<<"plaintext:";
  13. cin>>m;
  14. cout<<"cidhertext:"<<endl;
  15. k=strlen(m);
  16. for(i=0;i<k;i++){c[i]=m[i];c[i]=encrypt(c[i],e,n);cout<<c[i]<<" ";}
  17. system("pause");
  18. return 0;
  19. }