Calculate the entropy of a chunk of data.
(self, data)
| 1322 | return md5(self.get_data()).hexdigest() |
| 1323 | |
| 1324 | def entropy_H(self, data): |
| 1325 | """Calculate the entropy of a chunk of data.""" |
| 1326 | |
| 1327 | if not data: |
| 1328 | return 0.0 |
| 1329 | |
| 1330 | occurences = Counter(bytearray(data)) |
| 1331 | |
| 1332 | entropy = 0 |
| 1333 | for x in occurences.values(): |
| 1334 | p_x = float(x) / len(data) |
| 1335 | entropy -= p_x * math.log(p_x, 2) |
| 1336 | |
| 1337 | return entropy |
| 1338 | |
| 1339 | |
| 1340 | @lru_cache(maxsize=2048, copy=False) |