Inverse Modular function
(a, m int64)
| 19 | |
| 20 | // Inverse Modular function |
| 21 | func Inverse(a, m int64) (int64, error) { |
| 22 | gcd, x, _ := gcd.Extended(a, m) |
| 23 | if gcd != 1 || m == 0 { |
| 24 | return 0, ErrorInverse |
| 25 | } |
| 26 | |
| 27 | return ((m + (x % m)) % m), nil // this is necessary because of Go's use of architecture specific instruction for the % operator. |
| 28 | } |