mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 07:16:17 -04:00
Support UTF8 encoded characters in Substitution operation
This adds support for UTF8-encoded characters in the input and the parameters.
This commit is contained in:
parent
477e4a7421
commit
5b68bad185
1 changed files with 5 additions and 5 deletions
|
@ -44,8 +44,8 @@ class Substitute extends Operation {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const plaintext = Utils.expandAlphRange(args[0]).join(""),
|
const plaintext = Utils.expandAlphRange([...args[0]]),
|
||||||
ciphertext = Utils.expandAlphRange(args[1]).join("");
|
ciphertext = Utils.expandAlphRange([...args[1]]);
|
||||||
let output = "",
|
let output = "",
|
||||||
index = -1;
|
index = -1;
|
||||||
|
|
||||||
|
@ -53,9 +53,9 @@ class Substitute extends Operation {
|
||||||
output = "Warning: Plaintext and Ciphertext lengths differ\n\n";
|
output = "Warning: Plaintext and Ciphertext lengths differ\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < input.length; i++) {
|
for (const character of input) {
|
||||||
index = plaintext.indexOf(input[i]);
|
index = plaintext.indexOf(character);
|
||||||
output += index > -1 && index < ciphertext.length ? ciphertext[index] : input[i];
|
output += index > -1 && index < ciphertext.length ? ciphertext[index] : character;
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue