mirror of
https://github.com/swc-project/swc.git
synced 2024-12-26 07:02:28 +03:00
14 lines
334 B
TypeScript
14 lines
334 B
TypeScript
// Loaded from https://deno.land/x/god_crypto@v1.4.3/src/math.ts
|
|
|
|
|
|
export function power_mod(n: bigint, p: bigint, m: bigint): bigint {
|
|
if (p === 1n) return n;
|
|
if (p % 2n === 0n) {
|
|
const t = power_mod(n, p >> 1n, m);
|
|
return (t * t) % m;
|
|
} else {
|
|
const t = power_mod(n, p >> 1n, m);
|
|
return (t * t * n) % m;
|
|
}
|
|
}
|