好吧我正在尝试将字符串的基本转换器写md5入哈希代码,但是当我运行我的程序时,我不断收到错误信息:
Traceback (most recent call last):
File "C:\Users\Shane\Documents\Amer CISC\lab4.py", line 30, in <module>
assertEqual (computeMD5hash("The quick brown fox jumps over the lazy dog"),("9e107d9d372bb6826bd81d3542a419d6"))
File "C:\Users\Shane\Documents\Amer CISC\lab4.py", line 27, in computeMD5hash
m.update(string)
TypeError: Unicode-objects must be encoded before hashing
Run Code Online (Sandbox Code Playgroud)
我的代码看起来像这样:
def computeMD5hash(string):
import hashlib
from hashlib import md5
m = hashlib.md5()
m.update((string))
md5string=m.digest()
return md5string
Run Code Online (Sandbox Code Playgroud)