mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-23 08:16:17 -04:00
Merge branch 'bwhitn-chi'
This commit is contained in:
commit
99e0c8d5e3
4 changed files with 34 additions and 0 deletions
|
@ -302,6 +302,7 @@ const Categories = [
|
||||||
ops: [
|
ops: [
|
||||||
"Entropy",
|
"Entropy",
|
||||||
"Frequency distribution",
|
"Frequency distribution",
|
||||||
|
"Chi Square",
|
||||||
"Detect File Type",
|
"Detect File Type",
|
||||||
"Scan for Embedded Files",
|
"Scan for Embedded Files",
|
||||||
"Disassemble x86",
|
"Disassemble x86",
|
||||||
|
|
|
@ -3205,6 +3205,13 @@ const OperationConfig = {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"Chi Square": {
|
||||||
|
module: "Default",
|
||||||
|
description: "Calculates the Chi Square distribution of values.",
|
||||||
|
inputType: "byteArray",
|
||||||
|
outputType: "number",
|
||||||
|
args: []
|
||||||
|
},
|
||||||
"Numberwang": {
|
"Numberwang": {
|
||||||
module: "Default",
|
module: "Default",
|
||||||
description: "Based on the popular gameshow by Mitchell and Webb.",
|
description: "Based on the popular gameshow by Mitchell and Webb.",
|
||||||
|
|
|
@ -143,6 +143,7 @@ OpModules.Default = {
|
||||||
"Microsoft Script Decoder": MS.runDecodeScript,
|
"Microsoft Script Decoder": MS.runDecodeScript,
|
||||||
"Entropy": Entropy.runEntropy,
|
"Entropy": Entropy.runEntropy,
|
||||||
"Frequency distribution": Entropy.runFreqDistrib,
|
"Frequency distribution": Entropy.runFreqDistrib,
|
||||||
|
"Chi Square": Entropy.runChiSq,
|
||||||
"Detect File Type": FileType.runDetect,
|
"Detect File Type": FileType.runDetect,
|
||||||
"Scan for Embedded Files": FileType.runScanForEmbeddedFiles,
|
"Scan for Embedded Files": FileType.runScanForEmbeddedFiles,
|
||||||
"Generate UUID": UUID.runGenerateV4,
|
"Generate UUID": UUID.runGenerateV4,
|
||||||
|
|
|
@ -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.
|
* Calculates the Shannon entropy for a given chunk of data.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue