mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-22 07:46:16 -04:00
ESM: Tidied up Set operations
This commit is contained in:
parent
955a082614
commit
e99331f305
12 changed files with 81 additions and 487 deletions
|
@ -1,197 +0,0 @@
|
|||
import FlowControl from "../../FlowControl.js";
|
||||
import Arithmetic from "../../operations/Arithmetic.js";
|
||||
import Base from "../../operations/Base.js";
|
||||
import Base58 from "../../operations/Base58.js";
|
||||
import Base64 from "../../operations/Base64.js";
|
||||
import BCD from "../../operations/BCD.js";
|
||||
import BitwiseOp from "../../operations/BitwiseOp.js";
|
||||
import ByteRepr from "../../operations/ByteRepr.js";
|
||||
import Convert from "../../operations/Convert.js";
|
||||
import DateTime from "../../operations/DateTime.js";
|
||||
import Endian from "../../operations/Endian.js";
|
||||
import Entropy from "../../operations/Entropy.js";
|
||||
import Filetime from "../../operations/Filetime.js";
|
||||
import FileType from "../../operations/FileType.js";
|
||||
import Hexdump from "../../operations/Hexdump.js";
|
||||
import HTML from "../../operations/HTML.js";
|
||||
import MAC from "../../operations/MAC.js";
|
||||
import MorseCode from "../../operations/MorseCode.js";
|
||||
import MS from "../../operations/MS.js";
|
||||
import NetBIOS from "../../operations/NetBIOS.js";
|
||||
import Numberwang from "../../operations/Numberwang.js";
|
||||
import OS from "../../operations/OS.js";
|
||||
import OTP from "../../operations/OTP.js";
|
||||
import PHP from "../../operations/PHP.js";
|
||||
import QuotedPrintable from "../../operations/QuotedPrintable.js";
|
||||
import Rotate from "../../operations/Rotate.js";
|
||||
import SeqUtils from "../../operations/SeqUtils.js";
|
||||
import StrUtils from "../../operations/StrUtils.js";
|
||||
import Tidy from "../../operations/Tidy.js";
|
||||
import Unicode from "../../operations/Unicode.js";
|
||||
import UUID from "../../operations/UUID.js";
|
||||
import XKCD from "../../operations/XKCD.js";
|
||||
|
||||
|
||||
/**
|
||||
* Default module.
|
||||
*
|
||||
* The Default module is for operations that are expected to be very commonly used or
|
||||
* do not require any libraries. This module is loaded into the app at compile time.
|
||||
*
|
||||
* Libraries:
|
||||
* - Utils.js
|
||||
* - otp
|
||||
* - crypto
|
||||
* - bignumber.js
|
||||
*
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2017
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
const OpModules = typeof self === "undefined" ? {} : self.OpModules || {};
|
||||
|
||||
OpModules.Default = {
|
||||
"To Hexdump": Hexdump.runTo,
|
||||
"From Hexdump": Hexdump.runFrom,
|
||||
"To Hex": ByteRepr.runToHex,
|
||||
"From Hex": ByteRepr.runFromHex,
|
||||
"To Octal": ByteRepr.runToOct,
|
||||
"From Octal": ByteRepr.runFromOct,
|
||||
"To Charcode": ByteRepr.runToCharcode,
|
||||
"From Charcode": ByteRepr.runFromCharcode,
|
||||
"To Decimal": ByteRepr.runToDecimal,
|
||||
"From Decimal": ByteRepr.runFromDecimal,
|
||||
"To Binary": ByteRepr.runToBinary,
|
||||
"From Binary": ByteRepr.runFromBinary,
|
||||
"To Hex Content": ByteRepr.runToHexContent,
|
||||
"From Hex Content": ByteRepr.runFromHexContent,
|
||||
"To Base64": Base64.runTo,
|
||||
"From Base64": Base64.runFrom,
|
||||
"Show Base64 offsets": Base64.runOffsets,
|
||||
"To Base32": Base64.runTo32,
|
||||
"From Base32": Base64.runFrom32,
|
||||
"To Base58": Base58.runTo,
|
||||
"From Base58": Base58.runFrom,
|
||||
"To Base": Base.runTo,
|
||||
"From Base": Base.runFrom,
|
||||
"To BCD": BCD.runToBCD,
|
||||
"From BCD": BCD.runFromBCD,
|
||||
"To HTML Entity": HTML.runToEntity,
|
||||
"From HTML Entity": HTML.runFromEntity,
|
||||
"Strip HTML tags": HTML.runStripTags,
|
||||
"Parse colour code": HTML.runParseColourCode,
|
||||
"Unescape Unicode Characters": Unicode.runUnescape,
|
||||
"To Quoted Printable": QuotedPrintable.runTo,
|
||||
"From Quoted Printable": QuotedPrintable.runFrom,
|
||||
"Swap endianness": Endian.runSwapEndianness,
|
||||
"ROT13": Rotate.runRot13,
|
||||
"ROT47": Rotate.runRot47,
|
||||
"Rotate left": Rotate.runRotl,
|
||||
"Rotate right": Rotate.runRotr,
|
||||
"Bit shift left": BitwiseOp.runBitShiftLeft,
|
||||
"Bit shift right": BitwiseOp.runBitShiftRight,
|
||||
"XOR": BitwiseOp.runXor,
|
||||
"XOR Brute Force": BitwiseOp.runXorBrute,
|
||||
"OR": BitwiseOp.runOr,
|
||||
"NOT": BitwiseOp.runNot,
|
||||
"AND": BitwiseOp.runAnd,
|
||||
"ADD": BitwiseOp.runAdd,
|
||||
"SUB": BitwiseOp.runSub,
|
||||
"To Morse Code": MorseCode.runTo,
|
||||
"From Morse Code": MorseCode.runFrom,
|
||||
"Format MAC addresses": MAC.runFormat,
|
||||
"Encode NetBIOS Name": NetBIOS.runEncodeName,
|
||||
"Decode NetBIOS Name": NetBIOS.runDecodeName,
|
||||
"Offset checker": StrUtils.runOffsetChecker,
|
||||
"To Upper case": StrUtils.runUpper,
|
||||
"To Lower case": StrUtils.runLower,
|
||||
"Split": StrUtils.runSplit,
|
||||
"Filter": StrUtils.runFilter,
|
||||
"Escape string": StrUtils.runEscape,
|
||||
"Unescape string": StrUtils.runUnescape,
|
||||
"Head": StrUtils.runHead,
|
||||
"Tail": StrUtils.runTail,
|
||||
"Hamming Distance": StrUtils.runHamming,
|
||||
"Remove whitespace": Tidy.runRemoveWhitespace,
|
||||
"Remove null bytes": Tidy.runRemoveNulls,
|
||||
"Drop bytes": Tidy.runDropBytes,
|
||||
"Take bytes": Tidy.runTakeBytes,
|
||||
"Pad lines": Tidy.runPad,
|
||||
"Reverse": SeqUtils.runReverse,
|
||||
"Sort": SeqUtils.runSort,
|
||||
"Unique": SeqUtils.runUnique,
|
||||
"Count occurrences": SeqUtils.runCount,
|
||||
"Add line numbers": SeqUtils.runAddLineNumbers,
|
||||
"Remove line numbers": SeqUtils.runRemoveLineNumbers,
|
||||
"Expand alphabet range": SeqUtils.runExpandAlphRange,
|
||||
"Convert distance": Convert.runDistance,
|
||||
"Convert area": Convert.runArea,
|
||||
"Convert mass": Convert.runMass,
|
||||
"Convert speed": Convert.runSpeed,
|
||||
"Convert data units": Convert.runDataSize,
|
||||
"Parse UNIX file permissions": OS.runParseUnixPerms,
|
||||
"Parse DateTime": DateTime.runParse,
|
||||
"Translate DateTime Format": DateTime.runTranslateFormat,
|
||||
"From UNIX Timestamp": DateTime.runFromUnixTimestamp,
|
||||
"To UNIX Timestamp": DateTime.runToUnixTimestamp,
|
||||
"Sleep": DateTime.runSleep,
|
||||
"Microsoft Script Decoder": MS.runDecodeScript,
|
||||
"Entropy": Entropy.runEntropy,
|
||||
"Frequency distribution": Entropy.runFreqDistrib,
|
||||
"Chi Square": Entropy.runChiSq,
|
||||
"Detect File Type": FileType.runDetect,
|
||||
"Scan for Embedded Files": FileType.runScanForEmbeddedFiles,
|
||||
"Generate UUID": UUID.runGenerateV4,
|
||||
"Numberwang": Numberwang.run,
|
||||
"Generate TOTP": OTP.runTOTP,
|
||||
"Generate HOTP": OTP.runHOTP,
|
||||
"Fork": FlowControl.runFork,
|
||||
"Merge": FlowControl.runMerge,
|
||||
"Register": FlowControl.runRegister,
|
||||
"Label": FlowControl.runComment,
|
||||
"Jump": FlowControl.runJump,
|
||||
"Conditional Jump": FlowControl.runCondJump,
|
||||
"Return": FlowControl.runReturn,
|
||||
"Comment": FlowControl.runComment,
|
||||
"PHP Deserialize": PHP.runDeserialize,
|
||||
"Sum": Arithmetic.runSum,
|
||||
"Subtract": Arithmetic.runSub,
|
||||
"Multiply": Arithmetic.runMulti,
|
||||
"Divide": Arithmetic.runDiv,
|
||||
"Mean": Arithmetic.runMean,
|
||||
"Median": Arithmetic.runMedian,
|
||||
"Standard Deviation": Arithmetic.runStdDev,
|
||||
"Windows Filetime to UNIX Timestamp": Filetime.runFromFiletimeToUnix,
|
||||
"UNIX Timestamp to Windows Filetime": Filetime.runToFiletimeFromUnix,
|
||||
"XKCD Random Number": XKCD.runRandomNumber,
|
||||
|
||||
|
||||
/*
|
||||
Highlighting functions.
|
||||
|
||||
This is a temporary solution as highlighting should be entirely
|
||||
overhauled at some point.
|
||||
*/
|
||||
"From Base64-highlight": Base64.highlightFrom,
|
||||
"From Base64-highlightReverse": Base64.highlightTo,
|
||||
"To Base64-highlight": Base64.highlightTo,
|
||||
"To Base64-highlightReverse": Base64.highlightFrom,
|
||||
"From Hex-highlight": ByteRepr.highlightFrom,
|
||||
"From Hex-highlightReverse": ByteRepr.highlightTo,
|
||||
"To Hex-highlight": ByteRepr.highlightTo,
|
||||
"To Hex-highlightReverse": ByteRepr.highlightFrom,
|
||||
"From Charcode-highlight": ByteRepr.highlightFrom,
|
||||
"From Charcode-highlightReverse": ByteRepr.highlightTo,
|
||||
"To Charcode-highlight": ByteRepr.highlightTo,
|
||||
"To Charcode-highlightReverse": ByteRepr.highlightFrom,
|
||||
"From Binary-highlight": ByteRepr.highlightFromBinary,
|
||||
"From Binary-highlightReverse": ByteRepr.highlightToBinary,
|
||||
"To Binary-highlight": ByteRepr.highlightToBinary,
|
||||
"To Binary-highlightReverse": ByteRepr.highlightFromBinary,
|
||||
"From Hexdump-highlight": Hexdump.highlightFrom,
|
||||
"From Hexdump-highlightReverse": Hexdump.highlightTo,
|
||||
"To Hexdump-highlight": Hexdump.highlightTo,
|
||||
"To Hexdump-highlightReverse": Hexdump.highlightFrom,
|
||||
};
|
||||
|
||||
export default OpModules;
|
|
@ -4,7 +4,6 @@
|
|||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Utils from "../Utils";
|
||||
import Operation from "../Operation";
|
||||
|
||||
/**
|
||||
|
@ -20,14 +19,14 @@ class CartesianProduct extends Operation {
|
|||
|
||||
this.name = "Cartesian Product";
|
||||
this.module = "Default";
|
||||
this.description = "Get the cartesian product of two sets";
|
||||
this.description = "Calculates the cartesian product of multiple sets of data, returning all possible combinations.";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
name: "Sample delimiter",
|
||||
type: "binaryString",
|
||||
value: Utils.escapeHtml("\\n\\n")
|
||||
value: "\\n\\n"
|
||||
},
|
||||
{
|
||||
name: "Item delimiter",
|
||||
|
@ -39,19 +38,22 @@ class CartesianProduct extends Operation {
|
|||
|
||||
/**
|
||||
* Validate input length
|
||||
*
|
||||
* @param {Object[]} sets
|
||||
* @throws {Error} if not two sets
|
||||
* @throws {Error} if fewer than 2 sets
|
||||
*/
|
||||
validateSampleNumbers(sets) {
|
||||
if (!sets || (sets.length !== 2)) {
|
||||
if (!sets || sets.length < 2) {
|
||||
throw "Incorrect number of sets, perhaps you need to modify the sample delimiter or add more samples?";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the product operation
|
||||
* @param input
|
||||
* @param args
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
[this.sampleDelim, this.itemDelimiter] = args;
|
||||
|
@ -63,7 +65,7 @@ class CartesianProduct extends Operation {
|
|||
return e;
|
||||
}
|
||||
|
||||
return Utils.escapeHtml(this.runCartesianProduct(...sets.map(s => s.split(this.itemDelimiter))));
|
||||
return this.runCartesianProduct(...sets.map(s => s.split(this.itemDelimiter)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,12 +73,23 @@ class CartesianProduct extends Operation {
|
|||
*
|
||||
* @param {Object[]} a
|
||||
* @param {Object[]} b
|
||||
* @returns {String[]}
|
||||
* @param {Object[]} c
|
||||
* @returns {string}
|
||||
*/
|
||||
runCartesianProduct(a, b) {
|
||||
return Array(Math.max(a.length, b.length))
|
||||
.fill(null)
|
||||
.map((item, index) => `(${a[index] || undefined},${b[index] || undefined})`)
|
||||
runCartesianProduct(a, b, ...c) {
|
||||
/**
|
||||
* https://stackoverflow.com/a/43053803/7200497
|
||||
* @returns {Object[]}
|
||||
*/
|
||||
const f = (a, b) => [].concat(...a.map(d => b.map(e => [].concat(d, e))));
|
||||
/**
|
||||
* https://stackoverflow.com/a/43053803/7200497
|
||||
* @returns {Object[][]}
|
||||
*/
|
||||
const cartesian = (a, b, ...c) => (b ? cartesian(f(a, b), ...c) : a);
|
||||
|
||||
return cartesian(a, b, ...c)
|
||||
.map(set => `(${set.join(",")})`)
|
||||
.join(this.itemDelimiter);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Utils from "../Utils";
|
||||
import Operation from "../Operation";
|
||||
|
||||
/**
|
||||
|
@ -20,7 +19,7 @@ class PowerSet extends Operation {
|
|||
|
||||
this.name = "Power Set";
|
||||
this.module = "Default";
|
||||
this.description = "Generate the power set of a set";
|
||||
this.description = "Calculates all the subsets of a set.";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
|
@ -34,8 +33,10 @@ class PowerSet extends Operation {
|
|||
|
||||
/**
|
||||
* Generate the power set
|
||||
* @param input
|
||||
* @param args
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
[this.itemDelimiter] = args;
|
||||
|
@ -43,7 +44,7 @@ class PowerSet extends Operation {
|
|||
const inputArray = input.split(this.itemDelimiter).filter(a => a);
|
||||
|
||||
if (inputArray.length) {
|
||||
return Utils.escapeHtml(this.runPowerSet(inputArray));
|
||||
return this.runPowerSet(inputArray);
|
||||
}
|
||||
|
||||
return "";
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Utils from "../Utils";
|
||||
import Operation from "../Operation";
|
||||
|
||||
/**
|
||||
|
@ -20,14 +19,14 @@ class SetDifference extends Operation {
|
|||
|
||||
this.name = "Set Difference";
|
||||
this.module = "Default";
|
||||
this.description = "Get the Difference of two sets";
|
||||
this.description = "Calculates the difference of two sets.";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
name: "Sample delimiter",
|
||||
type: "binaryString",
|
||||
value: Utils.escapeHtml("\\n\\n")
|
||||
value: "\\n\\n"
|
||||
},
|
||||
{
|
||||
name: "Item delimiter",
|
||||
|
@ -39,6 +38,7 @@ class SetDifference extends Operation {
|
|||
|
||||
/**
|
||||
* Validate input length
|
||||
*
|
||||
* @param {Object[]} sets
|
||||
* @throws {Error} if not two sets
|
||||
*/
|
||||
|
@ -50,8 +50,10 @@ class SetDifference extends Operation {
|
|||
|
||||
/**
|
||||
* Run the difference operation
|
||||
* @param input
|
||||
* @param args
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
[this.sampleDelim, this.itemDelimiter] = args;
|
||||
|
@ -63,7 +65,7 @@ class SetDifference extends Operation {
|
|||
return e;
|
||||
}
|
||||
|
||||
return Utils.escapeHtml(this.runSetDifference(...sets.map(s => s.split(this.itemDelimiter))));
|
||||
return this.runSetDifference(...sets.map(s => s.split(this.itemDelimiter)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
import Utils from "../Utils";
|
||||
/**
|
||||
* @author d98762625 [d98762625@gmail.com]
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
|
||||
/**
|
||||
|
@ -14,14 +19,14 @@ class SetIntersection extends Operation {
|
|||
|
||||
this.name = "Set Intersection";
|
||||
this.module = "Default";
|
||||
this.description = "Get the intersection of two sets";
|
||||
this.description = "Calculates the intersection of two sets.";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
name: "Sample delimiter",
|
||||
type: "binaryString",
|
||||
value: Utils.escapeHtml("\\n\\n")
|
||||
value: "\\n\\n"
|
||||
},
|
||||
{
|
||||
name: "Item delimiter",
|
||||
|
@ -33,6 +38,7 @@ class SetIntersection extends Operation {
|
|||
|
||||
/**
|
||||
* Validate input length
|
||||
*
|
||||
* @param {Object[]} sets
|
||||
* @throws {Error} if not two sets
|
||||
*/
|
||||
|
@ -44,8 +50,10 @@ class SetIntersection extends Operation {
|
|||
|
||||
/**
|
||||
* Run the intersection operation
|
||||
* @param input
|
||||
* @param args
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
[this.sampleDelim, this.itemDelimiter] = args;
|
||||
|
@ -57,7 +65,7 @@ class SetIntersection extends Operation {
|
|||
return e;
|
||||
}
|
||||
|
||||
return Utils.escapeHtml(this.runIntersect(...sets.map(s => s.split(this.itemDelimiter))));
|
||||
return this.runIntersect(...sets.map(s => s.split(this.itemDelimiter)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Utils from "../Utils";
|
||||
import Operation from "../Operation";
|
||||
|
||||
/**
|
||||
|
@ -20,14 +19,14 @@ class SetUnion extends Operation {
|
|||
|
||||
this.name = "Set Union";
|
||||
this.module = "Default";
|
||||
this.description = "Get the union of two sets";
|
||||
this.description = "Calculates the union of two sets.";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
name: "Sample delimiter",
|
||||
type: "binaryString",
|
||||
value: Utils.escapeHtml("\\n\\n")
|
||||
value: "\\n\\n"
|
||||
},
|
||||
{
|
||||
name: "Item delimiter",
|
||||
|
@ -39,6 +38,7 @@ class SetUnion extends Operation {
|
|||
|
||||
/**
|
||||
* Validate input length
|
||||
*
|
||||
* @param {Object[]} sets
|
||||
* @throws {Error} if not two sets
|
||||
*/
|
||||
|
@ -50,8 +50,10 @@ class SetUnion extends Operation {
|
|||
|
||||
/**
|
||||
* Run the union operation
|
||||
* @param input
|
||||
* @param args
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
[this.sampleDelim, this.itemDelimiter] = args;
|
||||
|
@ -63,7 +65,7 @@ class SetUnion extends Operation {
|
|||
return e;
|
||||
}
|
||||
|
||||
return Utils.escapeHtml(this.runUnion(...sets.map(s => s.split(this.itemDelimiter))));
|
||||
return this.runUnion(...sets.map(s => s.split(this.itemDelimiter)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,7 +20,7 @@ class SymmetricDifference extends Operation {
|
|||
|
||||
this.name = "Symmetric Difference";
|
||||
this.module = "Default";
|
||||
this.description = "Get the symmetric difference of two sets";
|
||||
this.description = "Calculates the symmetric difference of two sets.";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
|
@ -39,6 +39,7 @@ class SymmetricDifference extends Operation {
|
|||
|
||||
/**
|
||||
* Validate input length
|
||||
*
|
||||
* @param {Object[]} sets
|
||||
* @throws {Error} if not two sets
|
||||
*/
|
||||
|
@ -50,8 +51,10 @@ class SymmetricDifference extends Operation {
|
|||
|
||||
/**
|
||||
* Run the difference operation
|
||||
* @param input
|
||||
* @param args
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
[this.sampleDelim, this.itemDelimiter] = args;
|
||||
|
@ -63,7 +66,7 @@ class SymmetricDifference extends Operation {
|
|||
return e;
|
||||
}
|
||||
|
||||
return Utils.escapeHtml(this.runSymmetricDifference(...sets.map(s => s.split(this.itemDelimiter))));
|
||||
return this.runSymmetricDifference(...sets.map(s => s.split(this.itemDelimiter)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue