From 5b68bad18568450cbbd2d42d40799e62185c2cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luke=20Sern=C3=A9?= Date: Fri, 13 May 2022 17:35:50 +0200 Subject: [PATCH] Support UTF8 encoded characters in Substitution operation This adds support for UTF8-encoded characters in the input and the parameters. --- src/core/operations/Substitute.mjs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/operations/Substitute.mjs b/src/core/operations/Substitute.mjs index 39f13e89..1afe1f42 100644 --- a/src/core/operations/Substitute.mjs +++ b/src/core/operations/Substitute.mjs @@ -44,8 +44,8 @@ class Substitute extends Operation { * @returns {string} */ run(input, args) { - const plaintext = Utils.expandAlphRange(args[0]).join(""), - ciphertext = Utils.expandAlphRange(args[1]).join(""); + const plaintext = Utils.expandAlphRange([...args[0]]), + ciphertext = Utils.expandAlphRange([...args[1]]); let output = "", index = -1; @@ -53,9 +53,9 @@ class Substitute extends Operation { output = "Warning: Plaintext and Ciphertext lengths differ\n\n"; } - for (let i = 0; i < input.length; i++) { - index = plaintext.indexOf(input[i]); - output += index > -1 && index < ciphertext.length ? ciphertext[index] : input[i]; + for (const character of input) { + index = plaintext.indexOf(character); + output += index > -1 && index < ciphertext.length ? ciphertext[index] : character; } return output;