fn mod_exp_pow(base: &BigUint, exp: &BigUint, md: &BigUint) -> BigUint {
    let mut res = BigUint::one();
    let (zero, one) = (BigUint::zero(), BigUint::one());
    let (mut base, mut exponent) = (base.clone(), exp.clone());

    while exponent > zero {
        if exponent.clone() & one.clone() > zero {
            res = (res * base.clone()) % md;
        }
        // Shifting 1 bit of the exponent as a binary number.
        exponent >>= 1;
        // Generating next base by squaring
        base = (base.clone() * base.clone()) % md;
    }
    res
}
// Modular exponentiation implemented on binary exponentiation (squaring)
Modular exponentiation implemented on binary exponentiation (squaring)
Modular exponentiation implemented on binary exponentiation ( squaring )
fn mod_exp_pow(base: &BigUint, exp: &BigUint, md: &BigUint) -> BigUint {
    let mut res = BigUint::one();
    let (zero, one) = (BigUint::zero(), BigUint::one());
    let (mut base, mut exponent) = (base.clone(), exp.clone());
    while exponent > zero {
        if exponent.clone() & one.clone() > zero {
            res = (res * base.clone()) % md;
        }
        // Shifting 1 bit of the exponent as a binary number.
        exponent >>= 1;
        // Generating next base by squaring
        base = (base.clone() * base.clone()) % md;
    }
    res
}
fn mod_exp_pow ( base : & BigUint , exp : & BigUint , md : & BigUint ) -> BigUint { let mut res = BigUint :: one ( ) ; let ( zero , one ) = ( BigUint :: zero ( ) , BigUint :: one ( ) ) ; let ( mut base , mut exponent ) = ( base . clone ( ) , exp . clone ( ) ) ; while exponent > zero { if exponent . clone ( ) & one . clone ( ) > zero { res = ( res * base . clone ( ) ) % md ; } // Shifting 1 bit of the exponent as a binary number. exponent >>= 1 ; // Generating next base by squaring base = ( base . clone ( ) * base . clone ( ) ) % md ; } res }
Modular exponentiation implemented on binary exponentiation (squaring)
Modular exponentiation implemented on binary exponentiation ( squaring )
base
&BigUint
exp
&BigUint
md
&BigUint