Fix ROT13 false behavior
ROT13 will produce false result when rotating numbers with negative amount.
This commit is contained in:
parent
18159ce806
commit
0da130597f
@ -59,11 +59,13 @@ class ROT13 extends Operation {
|
|||||||
rot13Upperacse = args[1],
|
rot13Upperacse = args[1],
|
||||||
rotNumbers = args[2];
|
rotNumbers = args[2];
|
||||||
let amount = args[3],
|
let amount = args[3],
|
||||||
|
numAmount = amount,
|
||||||
chr;
|
chr;
|
||||||
|
|
||||||
if (amount) {
|
if (amount) {
|
||||||
if (amount < 0) {
|
if (amount < 0) {
|
||||||
amount = 26 - (Math.abs(amount) % 26);
|
amount = 26 - (Math.abs(amount) % 26);
|
||||||
|
numAmount = 10 - (Math.abs(numAmount) % 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < input.length; i++) {
|
for (let i = 0; i < input.length; i++) {
|
||||||
@ -75,7 +77,7 @@ class ROT13 extends Operation {
|
|||||||
chr = (chr - 97 + amount) % 26;
|
chr = (chr - 97 + amount) % 26;
|
||||||
output[i] = chr + 97;
|
output[i] = chr + 97;
|
||||||
} else if (rotNumbers && chr >= 48 && chr <= 57) { // Numbers
|
} else if (rotNumbers && chr >= 48 && chr <= 57) { // Numbers
|
||||||
chr = (chr - 48 + amount) % 10;
|
chr = (chr - 48 + numAmount) % 10;
|
||||||
output[i] = chr + 48;
|
output[i] = chr + 48;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user