File tree Expand file tree Collapse file tree 4 files changed +31
-0
lines changed Expand file tree Collapse file tree 4 files changed +31
-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 . calcChiSq ,
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 @@ -163,6 +163,28 @@ const Entropy = {
163
163
return - entropy ;
164
164
} ,
165
165
166
+
167
+ /**
168
+ * Calculates the Chi Square distribution of values.
169
+ *
170
+ * @private
171
+ * @param {byteArray } data
172
+ * @param {Object[] } args
173
+ * @returns {number }
174
+ */
175
+ calcChiSq : function ( input , args ) {
176
+ let distArray = new Array ( 256 ) . fill ( 0 ) ,
177
+ total = 0 ;
178
+ for ( let i = 0 ; i < input . length ; i ++ ) {
179
+ distArray [ input [ i ] ] ++ ;
180
+ }
181
+ for ( let i = 0 ; i < distArray . length ; i ++ ) {
182
+ if ( distArray [ i ] > 0 ) {
183
+ total += Math . pow ( distArray [ i ] - input . length / 256 , 2 ) / ( input . length / 256 ) ;
184
+ }
185
+ }
186
+ return total ;
187
+ } ,
166
188
} ;
167
189
168
190
export default Entropy ;
You can’t perform that action at this time.
0 commit comments