mirror of
https://github.com/Alamantus/otp-generator.git
synced 2025-05-29 21:40:05 +02:00
Fix decrypt error, RE: negative modulo
This commit is contained in:
parent
a8bc9e7555
commit
e825dfc1d5
1 changed files with 3 additions and 1 deletions
4
index.js
4
index.js
|
@ -31,7 +31,9 @@ function decrypt(string, pad) {
|
||||||
return string.split('').map((letter, index) => {
|
return string.split('').map((letter, index) => {
|
||||||
const letterValue = CHARS.indexOf(letter);
|
const letterValue = CHARS.indexOf(letter);
|
||||||
const padValue = CHARS.indexOf(pad[index]);
|
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('');
|
}).join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue