我用 Python 编写了一些代码来检查文件中的 MD5 散列,并确保散列与原始散列匹配。
这是我开发的:
# Defines filename
filename = "file.exe"
# Gets MD5 from file
def getmd5(filename):
return m.hexdigest()
md5 = dict()
for fname in filename:
md5[fname] = getmd5(fname)
# If statement for alerting the user whether the checksum passed or failed
if md5 == '>md5 will go here<':
print("MD5 Checksum passed. You may now close this window")
input ("press enter")
else:
print("MD5 Checksum failed. Incorrect MD5 in file 'filename'. Please download a new copy")
input("press enter")
exit
但是每当我运行代码时,我都会收到以下错误:
Traceback (most recent call last):
File "C:\Users\Username\md5check.py", line 13, in <module>
md5[fname] = getmd5(fname)
File "C:\Users\Username\md5check.py, line 9, in getmd5
return m.hexdigest()
NameError: global name 'm' is not defined
我的代码中有什么遗漏吗?