diff --git a/index.js b/index.js index 91d8199..ec74736 100644 --- a/index.js +++ b/index.js @@ -31,7 +31,9 @@ function decrypt(string, pad) { return string.split('').map((letter, index) => { const letterValue = CHARS.indexOf(letter); const padValue = CHARS.indexOf(pad[index]); - return CHARS[(letterValue - padValue) % CHARS.length]; + let charIndex = (letterValue - padValue); + while (charIndex < 0) {charIndex += CHARS.length} + return CHARS[charIndex % CHARS.length]; }).join(''); }