Last active
October 21, 2021 16:07
-
-
Save SimonTheCoder/8aa6e2378ab66935170984638b2665a4 to your computer and use it in GitHub Desktop.
Calculate the entropy of a bytes array.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from scipy.stats import entropy | |
def bytes_entropy(target_bytes,base=None): | |
v,c = np.unique([int(i) for i in target_bytes],return_counts=True) | |
if base is None: | |
base = len(target_bytes) | |
if base >256: | |
base = 256 | |
return entropy(c,base=base) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment