Replace FME with addition chaining from Bruce Schneier

This commit is contained in:
jude 2023-02-27 20:08:50 +00:00
parent 62204634e1
commit 9e184e8aa6

View File

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