mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 23:36:16 -04:00
Merge branch 'port-arithmetic' of https://github.com/d98762625/CyberChef into esm
This commit is contained in:
commit
e41eb3d8a2
11 changed files with 2507 additions and 2007 deletions
51
src/core/operations/Divide.mjs
Normal file
51
src/core/operations/Divide.mjs
Normal file
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* @author bwhitn [brian.m.whitney@outlook.com]
|
||||
* @author d98762625 [d98762625@gmail.com]
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import BigNumber from "bignumber.js";
|
||||
import Operation from "../Operation";
|
||||
import { div, createNumArray } from "../lib/Arithmetic";
|
||||
import { ARITHMETIC_DELIM_OPTIONS } from "../lib/Delim";
|
||||
|
||||
|
||||
/**
|
||||
* Divide operation
|
||||
*/
|
||||
class Divide extends Operation {
|
||||
|
||||
/**
|
||||
* Divide constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Divide";
|
||||
this.module = "Default";
|
||||
this.description = "Divides a list of numbers. If an item in the string is not a number it is excluded from the list.<br><br>e.g. <code>0x0a 8 .5</code> becomes <code>2.5</code>";
|
||||
this.inputType = "string";
|
||||
this.outputType = "BigNumber";
|
||||
this.args = [
|
||||
{
|
||||
"name": "Delimiter",
|
||||
"type": "option",
|
||||
"value": ARITHMETIC_DELIM_OPTIONS,
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {BigNumber}
|
||||
*/
|
||||
run(input, args) {
|
||||
const val = div(createNumArray(input, args[0]));
|
||||
return val instanceof BigNumber ? val : new BigNumber(NaN);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Divide;
|
50
src/core/operations/Mean.mjs
Normal file
50
src/core/operations/Mean.mjs
Normal file
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* @author bwhitn [brian.m.whitney@outlook.com]
|
||||
* @author d98762625 [d98762625@gmail.com]
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import { mean, createNumArray } from "../lib/Arithmetic";
|
||||
import { ARITHMETIC_DELIM_OPTIONS } from "../lib/Delim";
|
||||
import BigNumber from "bignumber.js";
|
||||
|
||||
/**
|
||||
* Mean operation
|
||||
*/
|
||||
class Mean extends Operation {
|
||||
|
||||
/**
|
||||
* Mean constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Mean";
|
||||
this.module = "Default";
|
||||
this.description = "Computes the mean (average) of a number list. If an item in the string is not a number it is excluded from the list.<br><br>e.g. <code>0x0a 8 .5 .5</code> becomes <code>4.75</code>";
|
||||
this.inputType = "string";
|
||||
this.outputType = "BigNumber";
|
||||
this.args = [
|
||||
{
|
||||
"name": "Delimiter",
|
||||
"type": "option",
|
||||
"value": ARITHMETIC_DELIM_OPTIONS,
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {BigNumber}
|
||||
*/
|
||||
run(input, args) {
|
||||
const val = mean(createNumArray(input, args[0]));
|
||||
return val instanceof BigNumber ? val : new BigNumber(NaN);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Mean;
|
50
src/core/operations/Median.mjs
Normal file
50
src/core/operations/Median.mjs
Normal file
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* @author bwhitn [brian.m.whitney@outlook.com]
|
||||
* @author d98762625 [d98762625@gmail.com]
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import BigNumber from "bignumber.js";
|
||||
import Operation from "../Operation";
|
||||
import { median, createNumArray } from "../lib/Arithmetic";
|
||||
import { ARITHMETIC_DELIM_OPTIONS } from "../lib/Delim";
|
||||
|
||||
/**
|
||||
* Median operation
|
||||
*/
|
||||
class Median extends Operation {
|
||||
|
||||
/**
|
||||
* Median constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Median";
|
||||
this.module = "Default";
|
||||
this.description = "Computes the median of a number list. If an item in the string is not a number it is excluded from the list.<br><br>e.g. <code>0x0a 8 1 .5</code> becomes <code>4.5</code>";
|
||||
this.inputType = "string";
|
||||
this.outputType = "BigNumber";
|
||||
this.args = [
|
||||
{
|
||||
"name": "Delimiter",
|
||||
"type": "option",
|
||||
"value": ARITHMETIC_DELIM_OPTIONS,
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {BigNumber}
|
||||
*/
|
||||
run(input, args) {
|
||||
const val = median(createNumArray(input, args[0]));
|
||||
return val instanceof BigNumber ? val : new BigNumber(NaN);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Median;
|
51
src/core/operations/Multiply.mjs
Normal file
51
src/core/operations/Multiply.mjs
Normal file
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* @author bwhitn [brian.m.whitney@outlook.com]
|
||||
* @author d98762625 [d98762625@gmail.com]
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import BigNumber from "bignumber.js";
|
||||
import Operation from "../Operation";
|
||||
import { multi, createNumArray } from "../lib/Arithmetic";
|
||||
import { ARITHMETIC_DELIM_OPTIONS } from "../lib/Delim";
|
||||
|
||||
|
||||
/**
|
||||
* Multiply operation
|
||||
*/
|
||||
class Multiply extends Operation {
|
||||
|
||||
/**
|
||||
* Multiply constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Multiply";
|
||||
this.module = "Default";
|
||||
this.description = "Multiplies a list of numbers. If an item in the string is not a number it is excluded from the list.<br><br>e.g. <code>0x0a 8 .5</code> becomes <code>40</code>";
|
||||
this.inputType = "string";
|
||||
this.outputType = "BigNumber";
|
||||
this.args = [
|
||||
{
|
||||
"name": "Delimiter",
|
||||
"type": "option",
|
||||
"value": ARITHMETIC_DELIM_OPTIONS,
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {BigNumber}
|
||||
*/
|
||||
run(input, args) {
|
||||
const val = multi(createNumArray(input, args[0]));
|
||||
return val instanceof BigNumber ? val : new BigNumber(NaN);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Multiply;
|
52
src/core/operations/StandardDeviation.mjs
Normal file
52
src/core/operations/StandardDeviation.mjs
Normal file
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* @author bwhitn [brian.m.whitney@outlook.com]
|
||||
* @author d98762625 [d98762625@gmail.com]
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import BigNumber from "bignumber.js";
|
||||
import Operation from "../Operation";
|
||||
import { stdDev, createNumArray } from "../lib/Arithmetic";
|
||||
import { ARITHMETIC_DELIM_OPTIONS } from "../lib/Delim";
|
||||
|
||||
|
||||
/**
|
||||
* Standard Deviation operation
|
||||
*/
|
||||
class StandardDeviation extends Operation {
|
||||
|
||||
/**
|
||||
* StandardDeviation constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Standard Deviation";
|
||||
this.module = "Default";
|
||||
this.description = "Computes the standard deviation of a number list. If an item in the string is not a number it is excluded from the list.<br><br>e.g. <code>0x0a 8 .5</code> becomes <code>4.089281382128433</code>";
|
||||
this.inputType = "string";
|
||||
this.outputType = "BigNumber";
|
||||
this.args = [
|
||||
{
|
||||
"name": "Delimiter",
|
||||
"type": "option",
|
||||
"value": ARITHMETIC_DELIM_OPTIONS,
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {BigNumber}
|
||||
*/
|
||||
run(input, args) {
|
||||
const val = stdDev(createNumArray(input, args[0]));
|
||||
return val instanceof BigNumber ? val : new BigNumber(NaN);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default StandardDeviation;
|
51
src/core/operations/Subtract.mjs
Normal file
51
src/core/operations/Subtract.mjs
Normal file
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* @author bwhitn [brian.m.whitney@outlook.com]
|
||||
* @author d98762625 [d98762625@gmail.com]
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import BigNumber from "bignumber.js";
|
||||
import Operation from "../Operation";
|
||||
import { sub, createNumArray } from "../lib/Arithmetic";
|
||||
import { ARITHMETIC_DELIM_OPTIONS } from "../lib/Delim";
|
||||
|
||||
|
||||
/**
|
||||
* Subtract operation
|
||||
*/
|
||||
class Subtract extends Operation {
|
||||
|
||||
/**
|
||||
* Subtract constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Subtract";
|
||||
this.module = "Default";
|
||||
this.description = "Subtracts a list of numbers. If an item in the string is not a number it is excluded from the list.<br><br>e.g. <code>0x0a 8 .5</code> becomes <code>1.5</code>";
|
||||
this.inputType = "string";
|
||||
this.outputType = "BigNumber";
|
||||
this.args = [
|
||||
{
|
||||
"name": "Delimiter",
|
||||
"type": "option",
|
||||
"value": ARITHMETIC_DELIM_OPTIONS,
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {BigNumber}
|
||||
*/
|
||||
run(input, args) {
|
||||
const val = sub(createNumArray(input, args[0]));
|
||||
return val instanceof BigNumber ? val : new BigNumber(NaN);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Subtract;
|
50
src/core/operations/Sum.mjs
Normal file
50
src/core/operations/Sum.mjs
Normal file
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* @author bwhitn [brian.m.whitney@outlook.com]
|
||||
* @copyright Crown Copyright 2016
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import BigNumber from "bignumber.js";
|
||||
import Operation from "../Operation";
|
||||
import { sum, createNumArray } from "../lib/Arithmetic";
|
||||
import { ARITHMETIC_DELIM_OPTIONS } from "../lib/Delim";
|
||||
|
||||
|
||||
/**
|
||||
* Sum operation
|
||||
*/
|
||||
class Sum extends Operation {
|
||||
|
||||
/**
|
||||
* Sum constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Sum";
|
||||
this.module = "Default";
|
||||
this.description = "Adds together a list of numbers. If an item in the string is not a number it is excluded from the list.<br><br>e.g. <code>0x0a 8 .5</code> becomes <code>18.5</code>";
|
||||
this.inputType = "string";
|
||||
this.outputType = "BigNumber";
|
||||
this.args = [
|
||||
{
|
||||
"name": "Delimiter",
|
||||
"type": "option",
|
||||
"value": ARITHMETIC_DELIM_OPTIONS,
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {BigNumber}
|
||||
*/
|
||||
run(input, args) {
|
||||
const val = sum(createNumArray(input, args[0]));
|
||||
return val instanceof BigNumber ? val : new BigNumber(NaN);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Sum;
|
|
@ -1,3 +1,9 @@
|
|||
/**
|
||||
* @author d98762625 [d98762625@gmail.com]
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Utils from "../Utils.js";
|
||||
import BigNumber from "bignumber.js";
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue