MCPcopy Create free account
hub / github.com/TheAlgorithms/JavaScript / inverseMod

Function inverseMod

Ciphers/AffineCipher.js:26–30  ·  view source on GitHub ↗

* Modular multiplicative inverse * @param {Number} a - A coefficient * @param {Number} m - Modulos value * @return {Number} Return modular multiplicative inverse of coefficient a and modulos m

(a, m)

Source from the content-addressed store, hash-verified

24 * @return {Number} Return modular multiplicative inverse of coefficient a and modulos m
25 */
26function inverseMod(a, m) {
27 for (let x = 1; x < m; x++) {
28 if (mod(a * x, m) === 1) return x
29 }
30}
31
32/**
33 * Argument validation

Callers 1

decryptFunction · 0.85

Calls 1

modFunction · 0.85

Tested by

no test coverage detected