Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- unsigned long powmod( unsigned long base, int exp, int mod ) {
- base %= mod;
- unsigned long result = 1;
- while ( exp > 0 ) {
- if ( exp & 1 ) {
- result = ( result * base ) % mod;
- }
- base = ( base * base ) % mod;
- exp >>= 1;
- }
- return result;
- }
- int main( void ) {
- unsigned long msg;
- int e, n;
- cout << "MESSEAGE: ";
- cin >> msg;
- cout << "e (Public key): ";
- cin >> e;
- cout << "n (Public key): ";
- cin >> n;
- cout << "\nENCODED MESSAGE >> " << powmod( msg, e, n ) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement