def cmd_hasher(f, algorithm): """Compute various hashes for the input data, that can be a file or a stream. Example: \b $ habu.hasher README.rst md5 992a833cd162047daaa6a236b8ac15ae README.rst ripemd160 0566f9141e65e57cae93e0e3b70d1d8c2ccb0623 README.rst sha1 d7dbfd2c5e2828eb22f776550c826e4166526253 README.rst sha256 6bb22d927e1b6307ced616821a1877b6cc35e... README.rst sha512 8743f3eb12a11cf3edcc16e400fb14d599b4a... README.rst whirlpool 96bcc083242e796992c0f3462f330811f9e8c... README.rst You can also specify which algorithm to use. In such case, the output is only the value of the calculated hash: \b $ habu.hasher -a md5 README.rst 992a833cd162047daaa6a236b8ac15ae README.rst """ data = f.read() if not data: print("Empty file or string!") return 1 if algorithm: print(hasher(data, algorithm)[algorithm], f.name) else: for algo, result in hasher(data).items(): print("{:<12} {} {}".format(algo, result, f.name))
def cmd_hasher(f, algorithm): """Computes various hashes for the input data, that can be a file or a stream. Example: \b $ habu.hasher README.rst md5 e5828c564f71fea3a12dde8bd5d27063 README.rst ripemd160 ef6886c3b68cb34a44f9ca9336f3cd0732600a84 README.rst sha1 7bae8076a5771865123be7112468b79e9d78a640 README.rst sha512 65cfb1cf719b851b4aea5a7f5388068687b1fdfd290817a... README.rst whirlpool eaccf718b31d8a01f76fc08e896a6d0d73dbeafc2621fe0... README.rst You can also specify which algorithm to use. In such case, the output is only the value of the calculated hash: \b $ habu.hasher -a md5 README.rst e5828c564f71fea3a12dde8bd5d27063 README.rst """ data = f.read() if not data: print("Empty file or string!") return 1 if algorithm: print(hasher(data, algorithm)[algorithm], f.name) else: for algo, result in hasher(data).items(): print("{:<12} {} {}".format(algo, result, f.name))
def cmd_hasher(f, algorithm): """Hasher""" data = f.read() if not data: print("Empty file or string!") return 1 if algorithm: print(hasher(data, algorithm)[algorithm]) else: for algo, result in hasher(data).items(): print("{:<12}: {}".format(algo, result))