use happy_cracking::crypto::mathtools;
#[test]
fn test_gcd_basic() {
assert_eq!(mathtools::gcd(12, 8), 4);
assert_eq!(mathtools::gcd(54, 24), 6);
}
#[test]
fn test_gcd_coprime() {
assert_eq!(mathtools::gcd(17, 13), 1);
}
#[test]
fn test_gcd_with_zero() {
assert_eq!(mathtools::gcd(0, 5), 5);
assert_eq!(mathtools::gcd(5, 0), 5);
assert_eq!(mathtools::gcd(0, 0), 0);
}
#[test]
fn test_gcd_same() {
assert_eq!(mathtools::gcd(7, 7), 7);
}
#[test]
fn test_lcm_basic() {
assert_eq!(mathtools::lcm(4, 6), 12);
assert_eq!(mathtools::lcm(3, 5), 15);
}
#[test]
fn test_lcm_with_zero() {
assert_eq!(mathtools::lcm(0, 5), 0);
assert_eq!(mathtools::lcm(5, 0), 0);
}
#[test]
fn test_lcm_same() {
assert_eq!(mathtools::lcm(7, 7), 7);
}
#[test]
fn test_modinv_basic() {
assert_eq!(mathtools::modinv(3, 26).unwrap(), 9);
}
#[test]
fn test_modinv_known_values() {
assert_eq!(mathtools::modinv(7, 11).unwrap(), 8);
}
#[test]
fn test_modinv_not_exist() {
assert!(mathtools::modinv(2, 4).is_err());
}
#[test]
fn test_modinv_mod_one() {
assert_eq!(mathtools::modinv(5, 1).unwrap(), 0);
}
#[test]
fn test_modpow_basic() {
assert_eq!(mathtools::modpow(2, 10, 1000), 24);
}
#[test]
fn test_modpow_large() {
assert_eq!(mathtools::modpow(3, 13, 7), 3);
}
#[test]
fn test_modpow_zero_exp() {
assert_eq!(mathtools::modpow(5, 0, 13), 1);
}
#[test]
fn test_modpow_mod_one() {
assert_eq!(mathtools::modpow(100, 100, 1), 0);
}
#[test]
fn test_modpow_rsa_style() {
let n = 3233_u128;
let e = 17_u128;
let d = 2753_u128;
let message = 65_u128;
let encrypted = mathtools::modpow(message, e, n);
let decrypted = mathtools::modpow(encrypted, d, n);
assert_eq!(decrypted, message);
}