mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 15:26:16 -04:00
initial
This commit is contained in:
parent
d635cca210
commit
f81beea264
2 changed files with 54 additions and 1 deletions
|
@ -320,7 +320,8 @@
|
||||||
"Unescape string",
|
"Unescape string",
|
||||||
"Pseudo-Random Number Generator",
|
"Pseudo-Random Number Generator",
|
||||||
"Sleep",
|
"Sleep",
|
||||||
"File Tree"
|
"File Tree",
|
||||||
|
"Ngram"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
52
src/core/operations/Ngram.mjs
Normal file
52
src/core/operations/Ngram.mjs
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
/**
|
||||||
|
* @author benjcal [benj.calderon@gmail.com]
|
||||||
|
* @copyright Crown Copyright 2024
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Operation from "../Operation.mjs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ngram operation
|
||||||
|
*/
|
||||||
|
class Ngram extends Operation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ngram constructor
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.name = "Ngram";
|
||||||
|
this.module = "Default";
|
||||||
|
this.description = "Extracts n-grams from the input text. N-grams are contiguous sequences of n characters from a given text sample.";
|
||||||
|
this.infoURL = "https://wikipedia.org/wiki/N-gram";
|
||||||
|
this.inputType = "string";
|
||||||
|
this.outputType = "string";
|
||||||
|
this.args = [
|
||||||
|
{
|
||||||
|
name: "N-gram size",
|
||||||
|
type: "number",
|
||||||
|
value: 3
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
run(input, args) {
|
||||||
|
const n = args[0];
|
||||||
|
const ngrams = [];
|
||||||
|
for (let i = 0; i <= input.length - n; i++) {
|
||||||
|
ngrams.push(input.slice(i, i + n));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ngrams.join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Ngram;
|
Loading…
Add table
Add a link
Reference in a new issue