Commit 7c705dd9 by devttys0

Updated with faster shannon implementation from bjornedstrom

parent 8e092c40
...@@ -125,8 +125,14 @@ class Entropy(Module): ...@@ -125,8 +125,14 @@ class Entropy(Module):
entropy = 0 entropy = 0
if data: if data:
length = len(data)
seen = dict(((chr(x), 0) for x in range(0, 256)))
for byte in data:
seen[byte] += 1
for x in range(0, 256): for x in range(0, 256):
p_x = float(data.count(chr(x))) / len(data) p_x = float(seen[chr(x)]) / length
if p_x > 0: if p_x > 0:
entropy += - p_x*math.log(p_x, 2) entropy += - p_x*math.log(p_x, 2)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment