Skip to main content

mod_exp

Function mod_exp 

Source
pub fn mod_exp(base: u64, exp: u64, modulus: u64) -> u64
Expand description

Fast modular exponentiation base^exp mod modulus via repeated squaring.

Uses u128 intermediates so products of two u64-range operands cannot overflow. Returns 0 for modulus == 0 (degenerate) and handles modulus == 1 (everything is 0).