擅长:python、mysql、java
<p>你的问题是你正在使用同一个哈希对象,所以你只是不断地添加它。每次应该实例化一个新的sha512()对象。下面的代码工作正常。在</p>
<pre><code>import hashlib
h = hashlib.sha512()
text = 'beruk makye'
text_compare = '3beruk makye'
text_compare_hash = h.update(text_compare)
text_compare_hash = h.hexdigest()
ids = [1,2,3]
texts = []
bool_text = []
bool_text_hash = []
for id in ids:
texts.append(str(id) + text)
for i in texts:
hash = hashlib.sha512(i).hexdigest()
print i, hash, hash == text_compare_hash
</code></pre>