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

Function decrypt

Ciphers/AffineCipher.js:91–104  ·  view source on GitHub ↗

* Decrypt a Affine Cipher * @param {String} str - String to be decrypted * @param {Number} a - A coefficient * @param {Number} b - B coefficient * @return {String} result - Decrypted string

(str, a, b)

Source from the content-addressed store, hash-verified

89 * @return {String} result - Decrypted string
90 */
91function decrypt(str, a, b) {
92 let result = ''
93 if (isCorrectFormat(str, a, b)) {
94 str = str.split(' ')
95 for (let x = 0; x < str.length; x++) {
96 if (str[x] === '-1') result += ' '
97 else {
98 const charIndex = findCharIndex(str[x])
99 result += key[mod(inverseMod(a, 26) * (charIndex - b), 26)]
100 }
101 }
102 return result
103 }
104}
105export { encrypt, decrypt }

Callers 1

Calls 4

isCorrectFormatFunction · 0.85
findCharIndexFunction · 0.85
modFunction · 0.85
inverseModFunction · 0.85

Tested by

no test coverage detected