我已經報廢在一起一個程序,會出現亂碼字符組的定義爲:如何散列由用戶輸入定義的字符?
hash_object = hashlib.sha256(b'Test')
我想,使用戶輸入什麼是要散列,而不必每次都編輯程序我想要散列與「測試」不同的東西。
這是程序看起來現在的樣子,雖然第二行當前沒用,但是應該是我輸入要被散列的字符串的地方。
我該如何讓這個程序識別'x'作爲hash_object?
目前的方案:
import hashlib
x = input("")
hash_object = hashlib.sha256(b'Test')
hex_dig = hash_object.hexdigest()
print("Original hash : ", hex_dig)
print("Every 9 characters: ", hex_dig[::5])
wait = input()
用戶保羅·埃文斯問羯羊或不是,我可以使用
hash_object = hashlib.sha256(x)
,我不能,因爲它給了我這個錯誤:
Traceback (most recent call last):
File "C:\Users\einar_000\Desktop\Python\Hash.py", line 3, in <module>
hash_object = hashlib.sha256(x)
TypeError: Unicode-objects must be encoded before hashing
編輯約我的文章這個 – Rezic