Advertisement
cd62131

decryption.cpp

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