MCPcopy Create free account
hub / github.com/SourceCode-AI/aura / calculate_entropy

Function calculate_entropy

aura/analyzers/python/misc.py:85–98  ·  view source on GitHub ↗

Calculate shanon entropy of the string

(data: str, iterator=lambda: range(255))

Source from the content-addressed store, hash-verified

83
84
85def calculate_entropy(data: str, iterator=lambda: range(255)) -> float:
86 """
87 Calculate shanon entropy of the string
88 """
89 if not data:
90 return 0
91
92 entropy = 0
93 for x in iterator():
94 p_x = float(data.count(chr(x))) / len(data)
95 if p_x > 0:
96 entropy += -p_x * math.log(p_x, 2)
97
98 return entropy

Callers 1

node_StringMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected