Small tweaks to the arithmetic ops

This commit is contained in:
n1474335 2017-12-21 15:12:06 +00:00
parent c1fb6d9776
commit 98f59ace3a
3 changed files with 120 additions and 111 deletions

View File

@ -122,11 +122,6 @@ const Categories = [
"AND",
"ADD",
"SUB",
"Bit shift left",
"Bit shift right",
"Rotate left",
"Rotate right",
"ROT13",
"Sum",
"Subtract",
"Multiply",
@ -134,6 +129,11 @@ const Categories = [
"Mean",
"Median",
"Standard Deviation",
"Bit shift left",
"Bit shift right",
"Rotate left",
"Rotate right",
"ROT13",
]
},
{

View File

@ -520,6 +520,97 @@ const OperationConfig = {
}
]
},
"Sum": {
module: "Default",
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>",
inputType: "string",
outputType: "number",
args: [
{
name: "Delimiter",
type: "option",
value: Arithmetic.DELIM_OPTIONS
}
]
},
"Subtract": {
module: "Default",
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>",
inputType: "string",
outputType: "number",
args: [
{
name: "Delimiter",
type: "option",
value: Arithmetic.DELIM_OPTIONS
}
]
},
"Multiply": {
module: "Default",
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>",
inputType: "string",
outputType: "number",
args: [
{
name: "Delimiter",
type: "option",
value: Arithmetic.DELIM_OPTIONS
}
]
},
"Divide": {
module: "Default",
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>",
inputType: "string",
outputType: "number",
args: [
{
name: "Delimiter",
type: "option",
value: Arithmetic.DELIM_OPTIONS
}
]
},
"Mean": {
module: "Default",
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>",
inputType: "string",
outputType: "number",
args: [
{
name: "Delimiter",
type: "option",
value: Arithmetic.DELIM_OPTIONS
}
]
},
"Median": {
module: "Default",
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>",
inputType: "string",
outputType: "number",
args: [
{
name: "Delimiter",
type: "option",
value: Arithmetic.DELIM_OPTIONS
}
]
},
"Standard Deviation": {
module: "Default",
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>",
inputType: "string",
outputType: "number",
args: [
{
name: "Delimiter",
type: "option",
value: Arithmetic.DELIM_OPTIONS
}
]
},
"From Hex": {
module: "Default",
description: "Converts a hexadecimal byte string back into its raw value.<br><br>e.g. <code>ce 93 ce b5 ce b9 ce ac 20 cf 83 ce bf cf 85 0a</code> becomes the UTF-8 encoded string <code>Γειά σου</code>",
@ -677,97 +768,6 @@ const OperationConfig = {
}
]
},
"Sum": {
module: "Default",
description: "Sums 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>",
inputType: "string",
outputType: "string",
args: [
{
name: "Delimiter",
type: "option",
value: Arithmetic.DELIM_OPTIONS
}
]
},
"Subtract": {
module: "Default",
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>",
inputType: "string",
outputType: "string",
args: [
{
name: "Delimiter",
type: "option",
value: Arithmetic.DELIM_OPTIONS
}
]
},
"Multiply": {
module: "Default",
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>",
inputType: "string",
outputType: "string",
args: [
{
name: "Delimiter",
type: "option",
value: Arithmetic.DELIM_OPTIONS
}
]
},
"Divide": {
module: "Default",
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>",
inputType: "string",
outputType: "string",
args: [
{
name: "Delimiter",
type: "option",
value: Arithmetic.DELIM_OPTIONS
}
]
},
"Mean": {
module: "Default",
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>",
inputType: "string",
outputType: "string",
args: [
{
name: "Delimiter",
type: "option",
value: Arithmetic.DELIM_OPTIONS
}
]
},
"Median": {
module: "Default",
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>",
inputType: "string",
outputType: "string",
args: [
{
name: "Delimiter",
type: "option",
value: Arithmetic.DELIM_OPTIONS
}
]
},
"Standard Deviation": {
module: "Default",
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>",
inputType: "string",
outputType: "string",
args: [
{
name: "Delimiter",
type: "option",
value: Arithmetic.DELIM_OPTIONS
}
]
},
"From Hexdump": {
module: "Default",
description: "Attempts to convert a hexdump back into raw data. This operation supports many different hexdump variations, but probably not all. Make sure you verify that the data it gives you is correct before continuing analysis.",

View File

@ -1,5 +1,6 @@
import Utils from "../Utils.js";
/**
* Math operations on numbers.
*
@ -15,7 +16,7 @@ const Arithmetic = {
* @constant
* @default
*/
DELIM_OPTIONS: ["Space", "Comma", "Semi-colon", "Colon", "Line feed", "CRLF"],
DELIM_OPTIONS: ["Line feed", "Space", "Comma", "Semi-colon", "Colon", "CRLF"],
/**
@ -23,11 +24,11 @@ const Arithmetic = {
*
* @param {string} input
* @param {Object[]} args
* @returns {string}
* @returns {number}
*/
runSum: function(input, args) {
const val = Arithmetic._sum(Arithmetic._createNumArray(input, args[0]));
return typeof(val) === "number" ? val.toString() : "";
return typeof(val) === "number" ? val : NaN;
},
@ -36,11 +37,11 @@ const Arithmetic = {
*
* @param {string} input
* @param {Object[]} args
* @returns {string}
* @returns {number}
*/
runSub: function(input, args) {
let val = Arithmetic._sub(Arithmetic._createNumArray(input, args[0]));
return typeof(val) === "number" ? val.toString() : "";
return typeof(val) === "number" ? val : NaN;
},
@ -49,11 +50,11 @@ const Arithmetic = {
*
* @param {string} input
* @param {Object[]} args
* @returns {string}
* @returns {number}
*/
runMulti: function(input, args) {
let val = Arithmetic._multi(Arithmetic._createNumArray(input, args[0]));
return typeof(val) === "number" ? val.toString() : "";
return typeof(val) === "number" ? val : NaN;
},
@ -62,11 +63,11 @@ const Arithmetic = {
*
* @param {string} input
* @param {Object[]} args
* @returns {string}
* @returns {number}
*/
runDiv: function(input, args) {
let val = Arithmetic._div(Arithmetic._createNumArray(input, args[0]));
return typeof(val) === "number" ? val.toString() : "";
return typeof(val) === "number" ? val : NaN;
},
@ -75,11 +76,11 @@ const Arithmetic = {
*
* @param {string} input
* @param {Object[]} args
* @returns {string}
* @returns {number}
*/
runMean: function(input, args) {
let val = Arithmetic._mean(Arithmetic._createNumArray(input, args[0]));
return typeof(val) === "number" ? val.toString() : "";
return typeof(val) === "number" ? val : NaN;
},
@ -88,11 +89,11 @@ const Arithmetic = {
*
* @param {string} input
* @param {Object[]} args
* @returns {string}
* @returns {number}
*/
runMedian: function(input, args) {
let val = Arithmetic._median(Arithmetic._createNumArray(input, args[0]));
return typeof(val) === "number" ? val.toString() : "";
return typeof(val) === "number" ? val : NaN;
},
@ -101,17 +102,18 @@ const Arithmetic = {
*
* @param {string} input
* @param {Object[]} args
* @returns {string}
* @returns {number}
*/
runStdDev: function(input, args) {
let val = Arithmetic._stdDev(Arithmetic._createNumArray(input, args[0]));
return typeof(val) === "number" ? val.toString() : "";
return typeof(val) === "number" ? val : NaN;
},
/**
* Converts a string array to a number array.
*
* @private
* @param {string[]} input
* @param {string} delim
* @returns {number[]}
@ -121,6 +123,7 @@ const Arithmetic = {
let splitNumbers = input.split(delim),
numbers = [],
num;
for (let i = 0; i < splitNumbers.length; i++) {
if (splitNumbers[i].indexOf(".") >= 0) {
num = parseFloat(splitNumbers[i].trim());
@ -148,6 +151,7 @@ const Arithmetic = {
}
},
/**
* Subtracts an array of numbers and returns the value.
*
@ -161,6 +165,7 @@ const Arithmetic = {
}
},
/**
* Multiplies an array of numbers and returns the value.
*
@ -174,6 +179,7 @@ const Arithmetic = {
}
},
/**
* Divides an array of numbers and returns the value.
*
@ -187,6 +193,7 @@ const Arithmetic = {
}
},
/**
* Computes mean of a number array and returns the value.
*
@ -200,6 +207,7 @@ const Arithmetic = {
}
},
/**
* Computes median of a number array and returns the value.
*
@ -221,6 +229,7 @@ const Arithmetic = {
}
},
/**
* Computes standard deviation of a number array and returns the value.
*