Domanda

My code:

    for chars in chain(ALC, product(ALC, repeat=2), product(ALC, repeat=3)):
    a = hashlib.md5()
    a.update(chars.encode('utf-8'))
    print(''.join(chars))
    print(a.hexdigest())

It throws back:

Traceback (most recent call last):
File "pyCrack.py", line 18, in <module>
a.update(chars.encode('utf-8'))
AttributeError: 'tuple' object has no attribute 'encode'

Full output: http://pastebin.com/p1rEcn9H It appears to throw the error after tring to move on to "aa". How would I go about fixing this?

È stato utile?

Soluzione

You are chaining heterogeneous types together, which is a certain cause of headaches.

Presumably ALC is a string, so chain first yields all the characters from the string. When it moves on to product(ALC, repeat=2), it starts yielding tuples, since that's how product works.

Just yield homogeneous types from your chain call (i.e. always yield tuples, joining them when you need a string) and the headaches disappear.

for chars in chain(*[product(ALC, repeat=n) for n in range(1,4)]):
    ...
    a.update(''.join(chars).encode('utf-8'))

Altri suggerimenti

Your error is trying to convert this tuple to utf-8. Try remove this line "a.update(chars.encode('utf-8')"

When the interpreter shows "'tuple' object has no attribute 'encode' means that the object tuple does not support convert that way.

But, if you would like to convert all these things, use #coding: utf-8 in the first line of your program.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top