* 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)
| 89 | * @return {String} result - Decrypted string |
| 90 | */ |
| 91 | function 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 | } |
| 105 | export { encrypt, decrypt } |
no test coverage detected