Created
October 31, 2018 14:07
-
-
Save MattKovtun/7437afcb4cf76a4b989811e03b9beda2 to your computer and use it in GitHub Desktop.
Function for calculatin hash
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
import hashlib, sys, os | |
def calculate_hash(args): | |
BUF_SIZE = 65536 | |
file_name = args[0] | |
if not os.path.isfile(file_name): | |
return "Not a file" | |
sha1 = hashlib.sha1() | |
with open(file_name, 'rb') as f: | |
while True: | |
data = f.read(BUF_SIZE) | |
if not data: | |
break | |
sha1.update(data) | |
return sha1.hexdigest() | |
if __name__ == "__main__": | |
hsh = calculate_hash(sys.argv[1:]) | |
print(hsh) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment