3 pub fn powm(base: &BigUint, exp: &BigUint, modulus: &BigUint) -> BigUint {
4 let zero = BigUint::new(vec![0]);
5 let one = BigUint::new(vec![1]);
6 let two = BigUint::new(vec![2]);
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;