import sys import hashlib progName="hashTwice_v01.py" print("progName:",progName) #by D@CC #on 2023ISep25 #Hash Source: https://stackoverflow.com/questions/22058048/hashing-a-file-in-python # compare to: # $ md5-console -f bigfile # $ shasum bigfile #Snap Source:https://snapcraft.io/install/md5-console/raspbian # $ sudo apt update # $ sudo apt install snapd # then reboot # $ sudo snap install core # $ sudo snap install snapcraft --classic # $ sudo snap install md5-console # the last step took several minutes # BUF_SIZE is totally arbitrary, change for your app! BUF_SIZE = 65536 # lets read stuff in 64kb chunks! md5 = hashlib.md5() sha1 = hashlib.sha1() md5old=sys.argv[2] print("md5:",md5old) with open(sys.argv[1], 'rb') as f: while True: data = f.read(BUF_SIZE) if not data: break md5.update(data) sha1.update(data) # with end print("MD5: {0}".format(md5.hexdigest())) if md5old==md5.hexdigest() : print("md5 agrees") else: print("bad md5 hash") #if end print("SHA1: {0}".format(sha1.hexdigest()))