Skip to content

Instantly share code, notes, and snippets.

@jayswan
Created November 2, 2014 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jayswan/e821ed60914644e2e811 to your computer and use it in GitHub Desktop.
Save jayswan/e821ed60914644e2e811 to your computer and use it in GitHub Desktop.
import hashlib
def hash(s,a='md5'):
""" One-stop hex-digest of a string. Allows any algorithm supported by hashlib. """
f = getattr(hashlib,a)
return f(s).hexdigest()
def fhash(fn,a='md5'):
""" Hash a file as a string. Not memory considerate. """
with open(fn) as f:
contents = f.read()
return hash(contents,a)
def main():
pass
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment