title: How can I do a binary encoding of a string in python?
body: <p>I am trying to build an md5 cracker for practice. Before I go any further here is my code:</p>
  
  <pre><code>def offline_wordlist_attack(list_path):
        with fileinput.input(files=(list_path)) as wordlist:
            for word in wordlist:
                md5_hash_object = hashlib.md5() # constructing an md5 hash object
                md5_hash_object.update(binascii.a2b_uu(word))
                word_digest = md5_hash_object.digest() # performing the md5 digestion of the word   
                print(word_digest) # Debug
  </code></pre>
  
  <p>My issue is with <code>md5_hash_object.update(binascii.a2b_uu(word))</code>. The <a href="http://docs.python.org/py3k/library/hashlib.html" rel="noreferrer">hashlib</a> Python 3 documentation states that the string passed to <code>update()</code> should be in <strong>binary representation</strong>. The documentation uses <code>m.update(b"Nobody inspects")</code> as an example. In my code, I can not simply attach <code>b</code> in front of the variable <code>word</code>. So I tried to use the <a href="http://docs.python.org/py3k/library/binascii.html" rel="noreferrer">binascii</a> library, but that library too, has a note in the documentation stating:</p>
  
  <blockquote>
    <p>Note</p>
    
    <p>Encoding and decoding functions do not accept Unicode strings. Only
    bytestring and bytearray objects can be processed.</p>
  </blockquote>
  
  <p>Could somebody help me out with this? It is getting the better of me.</p>