Created
April 14, 2014 11:29
-
-
Save kozmonaut/10639701 to your computer and use it in GitHub Desktop.
Hashing with SHA256
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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