[][src]Function modpow::modpow

pub fn modpow<T: ToBigInt, U: ToBigInt>(base: &T, exp: &T, n: &U) -> BigInt

Calculate (base ** exp) % n.

NOTE: Function panics if exp < 0.

Examples

use modpow::*;
use num::bigint::*;
 
let base = BigInt::parse_bytes("4776913109852041418248056622882488319".as_bytes(), 10).unwrap();
let exp = BigInt::parse_bytes("195845982777569926302400511".as_bytes(), 10).unwrap();
let n = 100;

assert!(modpow(&base, &exp, &n) == 19.to_bigint().unwrap());