Advertisement
cd62131

encryption.cpp

Jan 27th, 2019
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. unsigned long powmod( unsigned long base, int exp, int mod ) {
  5.  
  6.   base %= mod;
  7.  
  8.   unsigned long result = 1;
  9.   while ( exp > 0 ) {
  10.  
  11.     if ( exp & 1 ) {
  12.       result = ( result * base ) % mod;
  13.     }
  14.     base = ( base * base ) % mod;
  15.     exp >>= 1;
  16.   }
  17.   return result;
  18. }
  19.  
  20. int main( void ) {
  21.  
  22.   unsigned long msg;
  23.   int e, n;
  24.  
  25.   cout << "MESSEAGE: ";
  26.   cin >> msg;
  27.  
  28.   cout << "e (Public key): ";
  29.   cin >> e;
  30.  
  31.   cout << "n (Public key): ";
  32.   cin >> n;
  33.  
  34.   cout << "\nENCODED MESSAGE >> " << powmod( msg, e, n ) << endl;
  35.  
  36.   return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement