Fix decrypt error, RE: negative modulo

This commit is contained in:
Robbie Antenesse 2018-02-20 22:54:38 -07:00
parent a8bc9e7555
commit e825dfc1d5
1 changed files with 3 additions and 1 deletions

View File

@ -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('');
}