Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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?
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'))
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.
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.