SHARE
TWEET

Untitled

a guest May 23rd, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdio.h"
  2.  
  3. int power_modulo_fast(int a, int b, int m)
  4. {
  5. int i;
  6. int result = 1;
  7. int x = a % m;
  8.  
  9. for (i=1; i<=b; i<<=1)
  10. {
  11.   x %= m;
  12.  
  13.     if ((b&i) != 0)
  14.       {
  15.     result *= x;
  16.     result %= m;
  17.       }
  18.  
  19.    x *= x;
  20. }
  21.  
  22.   return result;
  23. }
  24.  
  25. int decrypt_encrypt(int num, int Decrypt, int Encrypt, int PQ) {
  26.     printf("Decrypt op for %d\n", num);
  27.     int ctxt = power_modulo_fast(num, Encrypt, PQ);
  28.     printf("cipher num %d\n", ctxt);
  29.     int ctxt2 = power_modulo_fast(ctxt, Decrypt, PQ);
  30.     printf("decrypt num %d\n", ctxt2);
  31.     return 0;
  32. }
  33.  
  34. int main() {
  35.     int Decrypt = 157;
  36.     int Encrypt = 17;
  37.     int P = 47;
  38.     int Q = 59;
  39.     int PQ = P*Q;
  40.    
  41.     printf("Modulo %d\n", PQ);
  42.     decrypt_encrypt(920, Decrypt, Encrypt, PQ);
  43.     decrypt_encrypt(100, Decrypt, Encrypt, PQ);
  44.     decrypt_encrypt(1000, Decrypt, Encrypt, PQ);
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top