mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Merge pull request #1981 from bartblaze/master
This commit is contained in:
commit
d3357d2acd
2 changed files with 30 additions and 5 deletions
|
@ -18,7 +18,7 @@ class ConvertLeetSpeak extends Operation {
|
||||||
|
|
||||||
this.name = "Convert Leet Speak";
|
this.name = "Convert Leet Speak";
|
||||||
this.module = "Default";
|
this.module = "Default";
|
||||||
this.description = "Converts to and from Leet Speak";
|
this.description = "Converts to and from Leet Speak.";
|
||||||
this.infoURL = "https://wikipedia.org/wiki/Leet";
|
this.infoURL = "https://wikipedia.org/wiki/Leet";
|
||||||
this.inputType = "string";
|
this.inputType = "string";
|
||||||
this.outputType = "string";
|
this.outputType = "string";
|
||||||
|
@ -39,13 +39,16 @@ class ConvertLeetSpeak extends Operation {
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const direction = args[0];
|
const direction = args[0];
|
||||||
|
|
||||||
if (direction === "To Leet Speak") {
|
if (direction === "To Leet Speak") {
|
||||||
return input.replace(/[abcdefghijklmnopqrstuvwxyz]/gi, char => {
|
return input.replace(/[a-z]/gi, char => {
|
||||||
return toLeetMap[char.toLowerCase()] || char;
|
const leetChar = toLeetMap[char.toLowerCase()] || char;
|
||||||
|
return char === char.toUpperCase() ? leetChar.toUpperCase() : leetChar;
|
||||||
});
|
});
|
||||||
} else if (direction === "From Leet Speak") {
|
} else if (direction === "From Leet Speak") {
|
||||||
return input.replace(/[48cd3f6h1jklmn0pqr57uvwxyz]/g, char => {
|
return input.replace(/[48cd3f6h1jklmn0pqr57uvwxyz]/gi, char => {
|
||||||
return fromLeetMap[char] || char;
|
const normalChar = fromLeetMap[char] || char;
|
||||||
|
return normalChar;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,28 @@ TestRegister.addTests([
|
||||||
args: ["From Leet Speak"]
|
args: ["From Leet Speak"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Convert to Leet Speak: basic text, keep case",
|
||||||
|
input: "HELLO",
|
||||||
|
expectedOutput: "H3LL0",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Convert Leet Speak",
|
||||||
|
args: ["To Leet Speak"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Convert from Leet Speak: basic leet, keep case",
|
||||||
|
input: "H3LL0",
|
||||||
|
expectedOutput: "HeLLo",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Convert Leet Speak",
|
||||||
|
args: ["From Leet Speak"]
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue