Function modulo_n_tools::pow_mod[][src]

pub fn pow_mod<T, U>(a: T, b: U, modulo: &T) -> T where
    T: From<u8>,
    for<'x> &'x T: Mul<Output = T> + Rem<Output = T>,
    U: Ord + ShrAssign<u8> + From<u8>,
    for<'x> &'x U: BitAnd<Output = U>, 
Expand description

$a^b \bmod n$

Input: $-\text{modulo} \leq a \leq \text{modulo}$, b is non-negative integer.
Output: $-\text{modulo} \leq x \leq \text{modulo}$

use modulo_n_tools::pow_mod;
assert_eq!(pow_mod(3, 4, &5), 1);
assert_eq!(pow_mod(2, 5, &6), 2);
assert_eq!(pow_mod(-2, 3, &4), 0);
assert_eq!(pow_mod(2, 3, &7), 1);