File tree Expand file tree Collapse file tree 4 files changed +34
-0
lines changed Expand file tree Collapse file tree 4 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -302,6 +302,7 @@ const Categories = [
302
302
ops : [
303
303
"Entropy" ,
304
304
"Frequency distribution" ,
305
+ "Chi Square" ,
305
306
"Detect File Type" ,
306
307
"Scan for Embedded Files" ,
307
308
"Disassemble x86" ,
Original file line number Diff line number Diff line change @@ -3205,6 +3205,13 @@ const OperationConfig = {
3205
3205
}
3206
3206
]
3207
3207
} ,
3208
+ "Chi Square" : {
3209
+ module : "Default" ,
3210
+ description : "Calculates the Chi Square distribution of values." ,
3211
+ inputType : "byteArray" ,
3212
+ outputType : "number" ,
3213
+ args : [ ]
3214
+ } ,
3208
3215
"Numberwang" : {
3209
3216
module : "Default" ,
3210
3217
description : "Based on the popular gameshow by Mitchell and Webb." ,
Original file line number Diff line number Diff line change @@ -143,6 +143,7 @@ OpModules.Default = {
143
143
"Microsoft Script Decoder" : MS . runDecodeScript ,
144
144
"Entropy" : Entropy . runEntropy ,
145
145
"Frequency distribution" : Entropy . runFreqDistrib ,
146
+ "Chi Square" : Entropy . runChiSq ,
146
147
"Detect File Type" : FileType . runDetect ,
147
148
"Scan for Embedded Files" : FileType . runScanForEmbeddedFiles ,
148
149
"Generate UUID" : UUID . runGenerateV4 ,
Original file line number Diff line number Diff line change @@ -135,6 +135,31 @@ const Entropy = {
135
135
} ,
136
136
137
137
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
+
138
163
/**
139
164
* Calculates the Shannon entropy for a given chunk of data.
140
165
*
You can’t perform that action at this time.
0 commit comments