コード:
import itertools
import string
import hashlib
def hash_f(x):
h = hashlib.md5(x)
return int(h.hexdigest(),base=16)
value = raw_input("Enter a value: ")
oneChar = [map(''.join, itertools.product(string.ascii_lowercase, repeat=1))]
twoChar = [map(''.join, itertools.product(string.ascii_lowercase, repeat=2))]
threeChar = [map(''.join, itertools.product(string.ascii_lowercase, repeat=3))]
possibleValues = oneChar + twoChar + threeChar
hashed_list = [int(hashlib.md5(x).hexdigest(), base=16) for x in possibleValues]
for x in hashed_list:
if hash_f(value) == x:
print "MATCH"
このコードを実行しようとすると発生するエラーは次のとおりです。
Traceback (most recent call last):
File "hash.py", line 18, in <module>
hashed_list = [int(hashlib.md5(x).hexdigest(), base=16) for x in possibleValues]
TypeError: must be string or buffer, not list
私の頭の中でこれを見ていくと、私が見ることができる唯一の問題はhashlibのエラーですが、possibleValuesの個々の値を循環しているという事実のために、それを否定するべきではありませんか?
すべての助けに大いに感謝します!