Fix decrypt error, RE: negative modulo
This commit is contained in:
parent
a8bc9e7555
commit
e825dfc1d5
4
index.js
4
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('');
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue