我刚刚制作了一个程序,在该程序中,您输入的任何文本都会向后吐出经过哈希处理的文本。但是,该程序不会打印非哈希文本,然后也不会哈希真实文本。
import hashlib
not_hashed = []
hashed = []
while True:
word_hash = input("Hello this is a python string convertor.\n"
"Any thing you say will be encoded using hashes\n"
"What is your message: ")
hashed.append(word_hash)
hash_object = hashlib.md5(word_hash.encode())
hashed.append(hash_object)
print("This is your message")
print("Not hashed: ")
print(not_hashed)
print("Hashed")
print(hashed)
答案 0 :(得分:0)
需要两次更改。查看注释行:
import hashlib
not_hashed = []
hashed = []
while True:
word_hash = raw_input("Hello this is a python string convertor.\nAny thing you say will be encoded using hashes\nWhat is your message: ")
not_hashed.append(word_hash) #Needs to append to 'not_hashed' rather than 'hashed'
hash_object = hashlib.md5(word_hash.encode())
hashed.append(hash_object.hexdigest()) #The md5 is a binary object 'hexdigest' will give you a human readable object
print("This is your message")
print("Not hashed: ")
print(not_hashed)
print("Hashed")
print(hashed)