Skip to content

Instantly share code, notes, and snippets.

@kozmonaut
Created April 14, 2014 11:29
Show Gist options
  • Save kozmonaut/10639701 to your computer and use it in GitHub Desktop.
Save kozmonaut/10639701 to your computer and use it in GitHub Desktop.
Hashing with SHA256
#!/usr/bin/env python3.0
import hashlib
import sys
algorithm = dict(
sha256 = lambda x: hashlib.sha256(x).hexdigest()
)
def usage():
print 'Usage: python hash.py sha256 [text-to-hash]'
if __name__ == '__main__':
try:
result = algorithm[sys.argv[1]]
except (KeyError, IndexError):
usage()
sys.exit(1)
if len(sys.argv) > 2:
text = sys.argv[2]
else:
text = sys.stdin.read()
print result(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment