* Encrypt a Affine Cipher * @param {String} str - String to be encrypted * @param {Number} a - A coefficient * @param {Number} b - B coefficient * @return {String} result - Encrypted string
(str, a, b)
| 70 | */ |
| 71 | |
| 72 | function encrypt(str, a, b) { |
| 73 | let result = '' |
| 74 | if (isCorrectFormat(str, a, b)) { |
| 75 | for (let x = 0; x < str.length; x++) { |
| 76 | const charIndex = findCharIndex(str[x]) |
| 77 | if (charIndex < 0) result += '-1' + ' ' |
| 78 | else result += key.charAt(mod(a * charIndex + b, 26)) + ' ' |
| 79 | } |
| 80 | } |
| 81 | return result.trim() |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Decrypt a Affine Cipher |
no test coverage detected