Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chi Square #217

Merged
merged 4 commits into from
Dec 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/core/config/Categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ const Categories = [
ops: [
"Entropy",
"Frequency distribution",
"Chi Square",
"Detect File Type",
"Scan for Embedded Files",
"Disassemble x86",
Expand Down
7 changes: 7 additions & 0 deletions src/core/config/OperationConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3186,6 +3186,13 @@ const OperationConfig = {
}
]
},
"Chi Square": {
module: "Default",
description: "Calculates the Chi Square distribution of values.",
inputType: "byteArray",
outputType: "number",
args: []
},
"Numberwang": {
module: "Default",
description: "Based on the popular gameshow by Mitchell and Webb.",
Expand Down
1 change: 1 addition & 0 deletions src/core/config/modules/Default.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ OpModules.Default = {
"Microsoft Script Decoder": MS.runDecodeScript,
"Entropy": Entropy.runEntropy,
"Frequency distribution": Entropy.runFreqDistrib,
"Chi Square": Entropy.calcChiSq,
"Detect File Type": FileType.runDetect,
"Scan for Embedded Files": FileType.runScanForEmbeddedFiles,
"Generate UUID": UUID.runGenerateV4,
Expand Down
22 changes: 22 additions & 0 deletions src/core/operations/Entropy.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,28 @@ 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;