Refactor modPow to BigIntUtils, update to use shared function
This commit is contained in:
parent
21ba3e4b31
commit
9dce060090
@ -6,31 +6,10 @@
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import { parseBigInt } from "../lib/BigIntUtils.mjs";
|
||||
|
||||
/* ---------- helper functions ---------- */
|
||||
|
||||
/**
|
||||
* modPow helper operation
|
||||
*/
|
||||
function modPow(base, exponent, modulus) {
|
||||
let result = 1n;
|
||||
base %= modulus;
|
||||
|
||||
while (exponent > 0n) {
|
||||
if (exponent & 1n) {
|
||||
result = (result * base) % modulus;
|
||||
}
|
||||
base = (base * base) % modulus;
|
||||
exponent >>= 1n;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
import { parseBigInt, modPow } from "../lib/BigIntUtils.mjs";
|
||||
|
||||
/* ---------- operation class ---------- */
|
||||
|
||||
|
||||
/**
|
||||
* Modular Exponentiation operation
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user