diff --git a/src/core/config/modules/Default.js b/src/core/config/modules/Default.js index cbed60c9..a0e8bd23 100644 --- a/src/core/config/modules/Default.js +++ b/src/core/config/modules/Default.js @@ -143,7 +143,7 @@ OpModules.Default = { "Microsoft Script Decoder": MS.runDecodeScript, "Entropy": Entropy.runEntropy, "Frequency distribution": Entropy.runFreqDistrib, - "Chi Square": Entropy.calcChiSq, + "Chi Square": Entropy.runChiSq, "Detect File Type": FileType.runDetect, "Scan for Embedded Files": FileType.runScanForEmbeddedFiles, "Generate UUID": UUID.runGenerateV4, diff --git a/src/core/operations/Entropy.js b/src/core/operations/Entropy.js index 6952010f..aa9ed0bc 100755 --- a/src/core/operations/Entropy.js +++ b/src/core/operations/Entropy.js @@ -135,6 +135,31 @@ const Entropy = { }, + /** + * Chi Square operation. + * + * @param {byteArray} data + * @param {Object[]} args + * @returns {number} + */ + runChiSq: function(input, args) { + let distArray = new Array(256).fill(0), + total = 0; + + for (let i = 0; i < input.length; i++) { + distArray[input[i]]++; + } + + for (let i = 0; i < distArray.length; i++) { + if (distArray[i] > 0) { + total += Math.pow(distArray[i] - input.length / 256, 2) / (input.length / 256); + } + } + + return total; + }, + + /** * Calculates the Shannon entropy for a given chunk of data. * @@ -163,28 +188,6 @@ const Entropy = { return -entropy; }, - - /** - * Calculates the Chi Square distribution of values. - * - * @private - * @param {byteArray} data - * @param {Object[]} args - * @returns {number} - */ - calcChiSq: function(input, args) { - let distArray = new Array(256).fill(0), - total = 0; - for (let i = 0; i < input.length; i++) { - distArray[input[i]]++; - } - for (let i = 0; i < distArray.length; i++) { - if (distArray[i] > 0) { - total += Math.pow(distArray[i] - input.length / 256, 2) / (input.length / 256); - } - } - return total; - }, }; export default Entropy;