1 use num_bigint::BigUint;
3 pub fn powm(base: &BigUint, exp: &BigUint, modulus: &BigUint) -> BigUint {
4 let zero = BigUint::from(0u32);
5 let one = BigUint::from(1u32);
6 let two = BigUint::from(2u32);
7 let mut exp = exp.clone();
8 let mut result = one.clone();
9 let mut base = base % modulus;
12 if &exp % &two == one {
13 result = (result * &base) % modulus;
16 base = (&base * &base) % modulus;