rust-modinverse
Small library for finding the modular multiplicative inverses. Also has an implementation of the extended Euclidean algorithm built in.
egcd
Implementation of the extended Euclidean algorithm.
The first argument should be smaller than the second. This is checked with an assert!()
.
use egcd;
let smaller = 3;
let larger = 26;
let = egcd;
assert_eq!; // Greatest common denominator
assert_eq!; // Bézout coefficient x
assert_eq!; // Bézout coefficient y
assert_eq!; // Make sure it all works out according to plan
modinverse
Function to calculate the modular multiplicative inverse of an integer a modulo m.
A modular multiplicative inverse may not exist. If that is the case, this function will return None
. Otherwise, the inverse will be returned wrapped up in a Some
.
use modinverse;
let does_exist = modinverse;
let does_not_exist = modinverse;
match does_exist
match does_not_exist