hash_3.py 548 B

123456789101112131415161718192021
  1. def hash(argc):
  2. """hash: various hashing functions.
  3. Usage:
  4. hash (md5|sha256) FILE
  5. hash (md5|sha256) --string STRING
  6. """
  7. if argc.args['FILE']:
  8. if argc.args['md5']:
  9. return md5(open(argc.args['FILE']).read())
  10. elif argc.args['sha256']:
  11. return sha256(open(argc.args['FILE']).read())
  12. elif argc.args['--string']:
  13. if argc.args['md5']:
  14. return md5(argc.args['STRING'])
  15. elif argc.args['sha256']:
  16. return sha256(argc.args['STRING'])