rsa1.cpp 446 B

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