Как исправить TypeError: объекты Unicode должны быть закодированы перед хешированием?Python

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Как исправить TypeError: объекты Unicode должны быть закодированы перед хешированием?

Сообщение Anonymous »

У меня такая ошибка:

Traceback (most recent call last):
File "python_md5_cracker.py", line 27, in
m.update(line)
TypeError: Unicode-objects must be encoded before hashing


когда я пытаюсь выполнить этот код в Python 3.2.2:

import hashlib, sys
m = hashlib.md5()
hash = ""
hash_file = input("What is the file name in which the hash resides? ")
wordlist = input("What is your wordlist? (Enter the file name) ")
try:
hashdocument = open(hash_file, "r")
except IOError:
print("Invalid file.")
raw_input()
sys.exit()
else:
hash = hashdocument.readline()
hash = hash.replace("\n", "")

try:
wordlistfile = open(wordlist, "r")
except IOError:
print("Invalid file.")
raw_input()
sys.exit()
else:
pass
for line in wordlistfile:
# Flush the buffer (this caused a massive problem when placed
# at the beginning of the script, because the buffer kept getting
# overwritten, thus comparing incorrect hashes)
m = hashlib.md5()
line = line.replace("\n", "")
m.update(line)
word_hash = m.hexdigest()
if word_hash == hash:
print("Collision! The word corresponding to the given hash is", line)
input()
sys.exit()

print("The hash given does not correspond to any supplied word in the wordlist.")
input()
sys.exit()


Подробнее здесь: https://stackoverflow.com/questions/758 ... re-hashing
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»