From 0da130597ff2afe190b9100d3f81ee673235167b Mon Sep 17 00:00:00 2001 From: ItisCaleb <40360126+ItisCaleb@users.noreply.github.com> Date: Wed, 29 May 2024 18:43:03 +0800 Subject: [PATCH] Fix ROT13 false behavior ROT13 will produce false result when rotating numbers with negative amount. --- src/core/operations/ROT13.mjs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/operations/ROT13.mjs b/src/core/operations/ROT13.mjs index 1d059565..15240d25 100644 --- a/src/core/operations/ROT13.mjs +++ b/src/core/operations/ROT13.mjs @@ -59,11 +59,13 @@ class ROT13 extends Operation { rot13Upperacse = args[1], rotNumbers = args[2]; let amount = args[3], + numAmount = amount, chr; if (amount) { if (amount < 0) { amount = 26 - (Math.abs(amount) % 26); + numAmount = 10 - (Math.abs(numAmount) % 10); } for (let i = 0; i < input.length; i++) { @@ -75,7 +77,7 @@ class ROT13 extends Operation { chr = (chr - 97 + amount) % 26; output[i] = chr + 97; } else if (rotNumbers && chr >= 48 && chr <= 57) { // Numbers - chr = (chr - 48 + amount) % 10; + chr = (chr - 48 + numAmount) % 10; output[i] = chr + 48; } }