Skip to content

Instantly share code, notes, and snippets.

@MattKovtun
Created October 31, 2018 14:07
Show Gist options
  • Save MattKovtun/7437afcb4cf76a4b989811e03b9beda2 to your computer and use it in GitHub Desktop.
Save MattKovtun/7437afcb4cf76a4b989811e03b9beda2 to your computer and use it in GitHub Desktop.
Function for calculatin hash
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