1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use ;
use ;
use crate;
/// Computes the multiplicative inverse of `a` modulo `m`, if it exists.
///
/// The inverse is the integer `x` in `[0, m)` such that:
///
/// ```text
/// a · x ≡ 1 (mod m)
/// ```
///
/// Returns `None` if `gcd(a, m) != 1`, since the inverse only exists
/// when `a` and `m` are coprime.
///
/// # Examples
/// ```
/// use cryptograph::math::multiplicative_inverse::multiplicative_inverse;
/// assert_eq!(multiplicative_inverse(3, 7), Some(5)); // 3·5 = 15 ≡ 1 (mod 7)
/// assert_eq!(multiplicative_inverse(78, 30), None); // gcd(78, 30) = 6
/// ```