File tree Expand file tree Collapse file tree 2 files changed +26
-23
lines changed Expand file tree Collapse file tree 2 files changed +26
-23
lines changed Original file line number Diff line number Diff line change @@ -143,7 +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
+ "Chi Square" : Entropy . runChiSq ,
147
147
"Detect File Type" : FileType . runDetect ,
148
148
"Scan for Embedded Files" : FileType . runScanForEmbeddedFiles ,
149
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
*
@@ -163,28 +188,6 @@ const Entropy = {
163
188
return - entropy ;
164
189
} ,
165
190
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
- } ,
188
191
} ;
189
192
190
193
export default Entropy ;
You can’t perform that action at this time.
0 commit comments