mirror of
https://github.com/gchq/CyberChef.git
synced 2026-02-03 05:50:46 -08:00
feat: add output type option for random integer generation operation
This commit is contained in:
parent
9f7d1bf0ad
commit
db86856f24
1 changed files with 21 additions and 2 deletions
|
|
@ -57,6 +57,11 @@ class PseudoRandomIntegerGenerator extends Operation {
|
|||
"name": "Delimiter",
|
||||
"type": "option",
|
||||
"value": DELIM_OPTIONS
|
||||
},
|
||||
{
|
||||
"name": "Output",
|
||||
"type": "option",
|
||||
"value": ["Raw", "Hex", "Decimal"]
|
||||
}
|
||||
];
|
||||
|
||||
|
|
@ -71,7 +76,7 @@ class PseudoRandomIntegerGenerator extends Operation {
|
|||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const [numInts, minInt, maxInt, delimiter] = args;
|
||||
const [numInts, minInt, maxInt, delimiter, outputType] = args;
|
||||
|
||||
if (minInt === null || maxInt === null) return "";
|
||||
|
||||
|
|
@ -96,9 +101,23 @@ class PseudoRandomIntegerGenerator extends Operation {
|
|||
for (let i = 0; i < numInts; i++) {
|
||||
const result = this._generateRandomValue(rejectionThreshold);
|
||||
const intValue = min + (result % range);
|
||||
output.push(intValue.toString());
|
||||
|
||||
switch (outputType) {
|
||||
case "Hex":
|
||||
output.push(intValue.toString(16));
|
||||
break;
|
||||
case "Decimal":
|
||||
output.push(intValue.toString(10));
|
||||
break;
|
||||
case "Raw":
|
||||
default:
|
||||
output.push(Utils.chr(intValue));
|
||||
}
|
||||
}
|
||||
|
||||
if (outputType === "Raw") {
|
||||
return output.join("");
|
||||
}
|
||||
return output.join(delim);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue