好的,我正在尝试编写一个将字符串转换为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
我的代码如下所示:
def computeMD5hash(string):
import hashlib
from hashlib import md5
m = hashlib.md5()
m.update((string))
md5string=m.digest()
return md5string