Skip to content

Instantly share code, notes, and snippets.

@aleroddepaz
Created June 11, 2013 23:49
Show Gist options
  • Save aleroddepaz/5761824 to your computer and use it in GitHub Desktop.
Save aleroddepaz/5761824 to your computer and use it in GitHub Desktop.
Script to verify data integrity using the MD5 hash.
import sys
import hashlib
from functools import partial
def md5sum(filename):
with open(filename, mode="rb") as f:
md5 = hashlib.md5()
buf_size = md5.block_size * 64
for buf in iter(partial(f.read, buf_size), b''):
md5.update(buf)
return md5.hexdigest()
if __name__ == "__main__":
if len(sys.argv) < 2:
print("USAGE: {} <file>".format(sys.argv[0]))
sys.exit(1)
try:
print(md5sum(sys.argv[1]))
except Exception as e:
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment