0

我目前有以下代码:

from itertools import permutations
import hashlib

def hash_f(x):
    h = hashlib.md5(x)
    return int(h.hexdigest(),base=16)

value = raw_input("Enter a value: ")
possibleValues = 'a'

for p in permutations(possibleValues):
    if hash_f(value) == hash_f(possibleValues):
        print "MATCH"

(permutations的导入和使用暂时是占位符,等解决了这个问题以后会用到更多)

我想知道的是是否可以遍历列表并将其值替换为该值的散列形式。使用我当前的hash_f(x)功能不适用于列表,这是这里的问题。

感谢您提前提供任何帮助,如果您需要更多信息,请告诉我!

4

1 回答 1

2

我不明白你的片段应该做什么,但你的问题似乎可以用列表理解来回答。

from hashlib import md5

input_list = ['a','b','c','d','e']

hashed_list = [int(md5(x).hexdigest(), base=16) for x in input_list]

# Do whatever you wanted to do with the list of hashes....
于 2013-01-28T22:45:11.490 回答