Skip to content

Commit 99e0c8d

Browse files
committed
Merge branch 'bwhitn-chi'
2 parents 80719ae + 7a951d8 commit 99e0c8d

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

src/core/config/Categories.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ const Categories = [
302302
ops: [
303303
"Entropy",
304304
"Frequency distribution",
305+
"Chi Square",
305306
"Detect File Type",
306307
"Scan for Embedded Files",
307308
"Disassemble x86",

src/core/config/OperationConfig.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3205,6 +3205,13 @@ const OperationConfig = {
32053205
}
32063206
]
32073207
},
3208+
"Chi Square": {
3209+
module: "Default",
3210+
description: "Calculates the Chi Square distribution of values.",
3211+
inputType: "byteArray",
3212+
outputType: "number",
3213+
args: []
3214+
},
32083215
"Numberwang": {
32093216
module: "Default",
32103217
description: "Based on the popular gameshow by Mitchell and Webb.",

src/core/config/modules/Default.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ OpModules.Default = {
143143
"Microsoft Script Decoder": MS.runDecodeScript,
144144
"Entropy": Entropy.runEntropy,
145145
"Frequency distribution": Entropy.runFreqDistrib,
146+
"Chi Square": Entropy.runChiSq,
146147
"Detect File Type": FileType.runDetect,
147148
"Scan for Embedded Files": FileType.runScanForEmbeddedFiles,
148149
"Generate UUID": UUID.runGenerateV4,

src/core/operations/Entropy.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,31 @@ const Entropy = {
135135
},
136136

137137

138+
/**
139+
* Chi Square operation.
140+
*
141+
* @param {byteArray} data
142+
* @param {Object[]} args
143+
* @returns {number}
144+
*/
145+
runChiSq: function(input, args) {
146+
let distArray = new Array(256).fill(0),
147+
total = 0;
148+
149+
for (let i = 0; i < input.length; i++) {
150+
distArray[input[i]]++;
151+
}
152+
153+
for (let i = 0; i < distArray.length; i++) {
154+
if (distArray[i] > 0) {
155+
total += Math.pow(distArray[i] - input.length / 256, 2) / (input.length / 256);
156+
}
157+
}
158+
159+
return total;
160+
},
161+
162+
138163
/**
139164
* Calculates the Shannon entropy for a given chunk of data.
140165
*

0 commit comments

Comments
 (0)