Skip to content

Instantly share code, notes, and snippets.

@therealmik
Last active August 29, 2015 13:57
Show Gist options
  • Save therealmik/9907580 to your computer and use it in GitHub Desktop.
Save therealmik/9907580 to your computer and use it in GitHub Desktop.
Simple byte frequency count
#!/usr/bin/python3
import numpy
import sys
def analyse(fd):
result = numpy.zeros(256, dtype=numpy.uint32)
while True:
data = fd.read(4096)
if len(data) == 0:
break
for c in data:
result[c] += 1
return result
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: " + sys.argv[0] + " <file>", file=sys.stderr)
sys.exit(1)
with open(sys.argv[1], "rb") as fd:
result = analyse(fd)
for r in result:
print(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment