Advertisement
gasaichan

RSA Decryption

Dec 16th, 2019
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const partition = N => {
  2.   for (let i = 1; i <= Math.sqrt(N); i++) {
  3.     if (isPrime(i) && N % i == 0) {
  4.       return [i, N / i];
  5.     }
  6.   }
  7. };
  8.  
  9. const isPrime = n => {
  10.   if (n <= 1) {
  11.     return false;
  12.   }
  13.  
  14.   for (let i = 2; i < n; i++) {
  15.     if (n % i == 0) {
  16.       return false;
  17.     }
  18.   }
  19.  
  20.   return true;
  21. };
  22.  
  23. const gcd = (a, b) => {
  24.   if (!b) {
  25.     return a;
  26.   }
  27.  
  28.   return gcd(b, a % b);
  29. };
  30.  
  31. const e = 127;
  32. const N = 1643;
  33.  
  34. const parts = partition(1643);
  35. const phi = (parts[0] - 1) * (parts[1] - 1);
  36.  
  37. for (let i = 1; i <= phi; i++) {
  38.   if ((i * e) % phi == 1) {
  39.     console.log(i);
  40.   }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement