Skip to content

Instantly share code, notes, and snippets.

@anch0vy
Created January 22, 2015 16:39
Show Gist options
  • Save anch0vy/9262fd78866efcc9c1ad to your computer and use it in GitHub Desktop.
Save anch0vy/9262fd78866efcc9c1ad to your computer and use it in GitHub Desktop.
import sys
import math
if __name__=='__main__':
for x in sys.argv[1:]:
counts=[0]*256
entropy=0
with open(x,'rb') as f:
fr=f.read()
for xx in fr:
counts[ord(xx)]+=1
for count in counts:
if count==0:
continue
p=1.0*count/len(fr)
entropy -=p * math.log(p, 256)
print '[*]%s : %f'%(x,entropy)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment