mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 07:16:17 -04:00
Merge 6d4b641227
into e48fc4c8d8
This commit is contained in:
commit
ac69f7d20d
4 changed files with 94 additions and 1 deletions
|
@ -326,7 +326,8 @@
|
||||||
"Unescape string",
|
"Unescape string",
|
||||||
"Pseudo-Random Number Generator",
|
"Pseudo-Random Number Generator",
|
||||||
"Sleep",
|
"Sleep",
|
||||||
"File Tree"
|
"File Tree",
|
||||||
|
"Wrap"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
47
src/core/operations/Wrap.mjs
Normal file
47
src/core/operations/Wrap.mjs
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
/**
|
||||||
|
* @author 0xff1ce [github.com/0xff1ce]
|
||||||
|
* @copyright Crown Copyright 2024
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Operation from "../Operation.mjs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap operation
|
||||||
|
*/
|
||||||
|
class Wrap extends Operation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap constructor
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.name = "Wrap";
|
||||||
|
this.module = "Default";
|
||||||
|
this.description = "Wraps the input text at a specified number of characters per line.";
|
||||||
|
this.inputType = "string";
|
||||||
|
this.outputType = "string";
|
||||||
|
this.args = [
|
||||||
|
{
|
||||||
|
"name": "Line Width",
|
||||||
|
"type": "number",
|
||||||
|
"value": 64,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
run(input, args) {
|
||||||
|
if (!input) return ""; // Handle empty input
|
||||||
|
const lineWidth = args[0];
|
||||||
|
const regex = new RegExp(`.{1,${lineWidth}}`, "g");
|
||||||
|
return input.match(regex).join("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Wrap;
|
|
@ -155,6 +155,7 @@ import "./tests/TranslateDateTimeFormat.mjs";
|
||||||
import "./tests/Typex.mjs";
|
import "./tests/Typex.mjs";
|
||||||
import "./tests/UnescapeString.mjs";
|
import "./tests/UnescapeString.mjs";
|
||||||
import "./tests/Unicode.mjs";
|
import "./tests/Unicode.mjs";
|
||||||
|
import "./tests/Wrap.mjs";
|
||||||
import "./tests/YARA.mjs";
|
import "./tests/YARA.mjs";
|
||||||
import "./tests/ParseCSR.mjs";
|
import "./tests/ParseCSR.mjs";
|
||||||
import "./tests/XXTEA.mjs";
|
import "./tests/XXTEA.mjs";
|
||||||
|
|
44
tests/operations/tests/Wrap.mjs
Normal file
44
tests/operations/tests/Wrap.mjs
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/**
|
||||||
|
* @author 0xff1ce [github.com/0xff1ce]
|
||||||
|
* @copyright Crown Copyright 2024
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import TestRegister from "../../lib/TestRegister.mjs";
|
||||||
|
|
||||||
|
TestRegister.addTests([
|
||||||
|
// Add tests specific to the Wrap operation
|
||||||
|
{
|
||||||
|
name: "Wrap text at 64 characters",
|
||||||
|
input: "A".repeat(128), // Generate an input string of 128 'A' characters
|
||||||
|
expectedOutput: "A".repeat(64) + "\n" + "A".repeat(64), // Expected output with a line break after 64 characters
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "Wrap",
|
||||||
|
"args": [64]
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Wrap text at 32 characters",
|
||||||
|
input: "B".repeat(96), // Generate an input string of 96 'B' characters
|
||||||
|
expectedOutput: "B".repeat(32) + "\n" + "B".repeat(32) + "\n" + "B".repeat(32), // Expected output with line breaks after every 32 characters
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "Wrap",
|
||||||
|
"args": [32]
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Wrap text at 10 characters",
|
||||||
|
input: "1234567890".repeat(10), // Generate an input string by repeating '1234567890'
|
||||||
|
expectedOutput: Array(10).fill("1234567890").join("\n"), // Expected output with line breaks every 10 characters
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "Wrap",
|
||||||
|
"args": [10]
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
]);
|
Loading…
Add table
Add a link
Reference in a new issue