0

I currently have the following code:

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"

(The import and use of permutations is a placeholder for now, it'll be used more once this problem is solved)

What I would like to know is whether or not it's possible to iterate through a list and replace its value with the hashed form of that value. Using my current hash_f(x) function doesn't work with lists, which is the problem here.

Thanks for advance for any help, and let me know if you need more information!

dantdj
  • 1,237
  • 3
  • 19
  • 40

1 Answers1

2

I'm not understanding what your snippet is supposed to do, but your question seems like it could be answered with a list comprehension.

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....
Lyndsy Simon
  • 5,208
  • 1
  • 17
  • 21
  • My snippet is currently (After updating it with your list comprehension and taking out the permutations) taking the hash of the value given by the user, comparing it to the values in the list, and seeing if they match. Ultimately, the goal for now is for it to be able to check this through every letter combination that can be produced with 3 characters. For example, aaa, dbr, asj, something like that. – dantdj Jan 28 '13 at 23:16