Replace FME with addition chaining from Bruce Schneier
This commit is contained in:
parent
62204634e1
commit
9e184e8aa6
@ -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;
|
||||
if (b % 2n === 1n) {
|
||||
res = (res * a) % n;
|
||||
}
|
||||
|
||||
b >>= 1n;
|
||||
|
||||
if (leastSignificantBit === 1n) {
|
||||
result = result * x;
|
||||
result = result % n;
|
||||
a = (a * a) % n;
|
||||
}
|
||||
|
||||
x = x * x;
|
||||
x = x % n;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
return res;
|
||||
}
|
||||
|
||||
const SMALL_PRIMES = [
|
||||
2n,
|
||||
|
Loading…
Reference in New Issue
Block a user