MCPcopy Create free account
hub / github.com/ELMERIKH/PyinMemoryPE / entropy_H

Method entropy_H

pythonmemorymodule/pefile.py:1324–1337  ·  view source on GitHub ↗

Calculate the entropy of a chunk of data.

(self, data)

Source from the content-addressed store, hash-verified

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)

Callers 1

get_entropyMethod · 0.95

Calls 1

valuesMethod · 0.45

Tested by

no test coverage detected