def pow_mod_odd

bend-collections-laws-crypto@1.0.0.0 · src/math/natural.bend:275

import bend-collections-laws-crypto@1.0.0.0/src/math/natural.bend as Natural
import Base

275# right-to-left binary exponentiation, reducing mod m after every product:
276# acc * base^e == b^e0 (mod m) throughout
277def pow_mod_odd(+m: Nat, +bit: Nat, +base: Nat, +acc: Nat) -> Nat:
278  match bit:
279    case 0n:
280      acc
281    case 1n+z:
282      Nat.mod(Nat.mul(acc, base), m)

Uses (3)

Used by (5)