Add Leet Speak
Not too many use cases, but something I thought of (and have seen in a few skiddie malware samples). Will also resolve #1234
This commit is contained in:
parent
3822c6c520
commit
f14c423c64
@ -268,7 +268,8 @@
|
||||
"Unicode Text Format",
|
||||
"Remove Diacritics",
|
||||
"Unescape Unicode Characters",
|
||||
"Convert to NATO alphabet"
|
||||
"Convert to NATO alphabet",
|
||||
"Convert Leet Speak"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
113
src/core/operations/ConvertLeetSpeak.mjs
Normal file
113
src/core/operations/ConvertLeetSpeak.mjs
Normal file
@ -0,0 +1,113 @@
|
||||
/**
|
||||
* @author bartblaze []
|
||||
* @copyright Crown Copyright 2025
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
|
||||
/**
|
||||
* Convert Leet Speak operation
|
||||
*/
|
||||
class ConvertLeetSpeak extends Operation {
|
||||
/**
|
||||
* ConvertLeetSpeak constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Convert Leet Speak";
|
||||
this.module = "Default";
|
||||
this.description = "Converts to and from Leet Speak";
|
||||
this.infoURL = "https://wikipedia.org/wiki/Leet";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
name: "Direction",
|
||||
type: "option",
|
||||
value: ["To Leet Speak", "From Leet Speak"],
|
||||
defaultIndex: 0
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const direction = args[0];
|
||||
if (direction === "To Leet Speak") {
|
||||
return input.replace(/[abcdefghijklmnopqrstuvwxyz]/gi, char => {
|
||||
return toLeetMap[char.toLowerCase()] || char;
|
||||
});
|
||||
} else if (direction === "From Leet Speak") {
|
||||
return input.replace(/[48cd3f6h1jklmn0pqr57uvwxyz]/g, char => {
|
||||
return fromLeetMap[char] || char;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const toLeetMap = {
|
||||
"a": "4",
|
||||
"b": "b",
|
||||
"c": "c",
|
||||
"d": "d",
|
||||
"e": "3",
|
||||
"f": "f",
|
||||
"g": "g",
|
||||
"h": "h",
|
||||
"i": "1",
|
||||
"j": "j",
|
||||
"k": "k",
|
||||
"l": "l",
|
||||
"m": "m",
|
||||
"n": "n",
|
||||
"o": "0",
|
||||
"p": "p",
|
||||
"q": "q",
|
||||
"r": "r",
|
||||
"s": "5",
|
||||
"t": "7",
|
||||
"u": "u",
|
||||
"v": "v",
|
||||
"w": "w",
|
||||
"x": "x",
|
||||
"y": "y",
|
||||
"z": "z"
|
||||
};
|
||||
|
||||
const fromLeetMap = {
|
||||
"4": "a",
|
||||
"b": "b",
|
||||
"c": "c",
|
||||
"d": "d",
|
||||
"3": "e",
|
||||
"f": "f",
|
||||
"g": "g",
|
||||
"h": "h",
|
||||
"1": "i",
|
||||
"j": "j",
|
||||
"k": "k",
|
||||
"l": "l",
|
||||
"m": "m",
|
||||
"n": "n",
|
||||
"0": "o",
|
||||
"p": "p",
|
||||
"q": "q",
|
||||
"r": "r",
|
||||
"5": "s",
|
||||
"7": "t",
|
||||
"u": "u",
|
||||
"v": "v",
|
||||
"w": "w",
|
||||
"x": "x",
|
||||
"y": "y",
|
||||
"z": "z"
|
||||
};
|
||||
|
||||
export default ConvertLeetSpeak;
|
||||
|
@ -54,6 +54,7 @@ import "./tests/Comment.mjs";
|
||||
import "./tests/Compress.mjs";
|
||||
import "./tests/ConditionalJump.mjs";
|
||||
import "./tests/ConvertCoordinateFormat.mjs";
|
||||
import "./tests/ConvertLeetSpeak.mjs";
|
||||
import "./tests/ConvertToNATOAlphabet.mjs";
|
||||
import "./tests/Crypt.mjs";
|
||||
import "./tests/CSV.mjs";
|
||||
|
33
tests/operations/tests/ConvertLeetSpeak.mjs
Normal file
33
tests/operations/tests/ConvertLeetSpeak.mjs
Normal file
@ -0,0 +1,33 @@
|
||||
/**
|
||||
* @author bartblaze []
|
||||
* @copyright Crown Copyright 2025
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Convert to Leet Speak: basic text",
|
||||
input: "leet",
|
||||
expectedOutput: "l337",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Convert Leet Speak",
|
||||
args: ["To Leet Speak"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Convert from Leet Speak: basic leet",
|
||||
input: "l337",
|
||||
expectedOutput: "leet",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Convert Leet Speak",
|
||||
args: ["From Leet Speak"]
|
||||
}
|
||||
]
|
||||
}
|
||||
]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user