فهرست منبع

Tidied up Chi Square operation

n1474335 7 سال پیش
والد
کامیت
7a951d86d8
2فایلهای تغییر یافته به همراه26 افزوده شده و 23 حذف شده
  1. 1 1
      src/core/config/modules/Default.js
  2. 25 22
      src/core/operations/Entropy.js

+ 1 - 1
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,

+ 25 - 22
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;