diff --git a/static/js/random_primes.js b/static/js/random_primes.js index 7abf1bc..0e8a2ff 100644 --- a/static/js/random_primes.js +++ b/static/js/random_primes.js @@ -86,26 +86,20 @@ function generate_prime() { } } -// gist.github.com/krzkaczor/0bdba0ee9555659ae5fe -var fastModularExponentiation = function (a, b, n) { - a = a % n; - var result = 1n; - var x = a; +function fastModularExponentiation(a, b, n) { + let res = 1n; while (b > 0n) { - var leastSignificantBit = b % 2n; - b >>= 1n; - - if (leastSignificantBit === 1n) { - result = result * x; - result = result % n; + if (b % 2n === 1n) { + res = (res * a) % n; } - x = x * x; - x = x % n; + b >>= 1n; + a = (a * a) % n; } - return result; -}; + + return res; +} const SMALL_PRIMES = [ 2n,