Function modulo_n_tools::mul_pow_mod[][src]

pub fn mul_pow_mod<T, U>(a: T, base: T, power: U, modulo: &T) -> T where
    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\cdot b^p \bmod n$

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

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