Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- std::vector<int> binaryVec;
- void binaryConvert(int number) {
- if (number > 0) {
- int bin = number % 2;
- number /= 2;
- binaryConvert(number);
- binaryVec.push_back(bin);
- }
- }
- // P( e, n ) -> public key
- // S( d, n ) -> secret key
- int main() {
- const int e = 11; // e is a number which is made by: biggest common divisor(e,f), where e and f are relative prime numbers, and f = (p-1) * (q-1)
- const int n = 899; // n is p*q, where p and q are prime numbers
- const int d = 611; // is the secret variable of the secret key
- long int M;
- long int result;
- std::cout << "give me a number" << std::endl;
- std::cin >> M;
- binaryConvert(M);
- int c = 1;
- for (int i = 0; i < binaryVec.size(); i++) {
- if (binaryVec[i] == 1) {
- c = (c*c) % n;
- c = (100 * c) % n;
- }
- else {
- c = (c*c) % n;
- }
- result = c;
- }
- std::cout << "result is " << result << std::endl;
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement