title: How do I get the correct hash values when reading a .txt wordlist line-by-line?
body: <p>I'm trying to build a Python3.x script that reads a .txt wordlist and convert the word on every line to its hashed equivalent however when I execute this script it produces a wrong hash.<br/><br/></p>
  
  <p>Hope you guys can help me figure out what I'm doing wrong here..</p>
  
  <h1>Output</h1>
  
  <pre><code>Arguments passed to the program:
  Namespace(inputHashType=['md5'], verbose=True, 
      wordlist=_io.TextIOWrapper name='C:\\Users\\Mikael\\Desktop\\wordlist.txt' mode='rt' encoding='utf-8')
  Verbose is set to: True
  
  correct hash:  b61a6d542f9036550ba9c401c80f00ef
  Line 1:  PT: tests      As hash: a58c6e40436bbb090294218b7d758a15
  </code></pre>
  
  <h1>Example of inputfile:</h1>
  
  <pre><code>tests
  tests1
  tests2
  </code></pre>
  
  <h1>Source Code</h1>
  
  <pre><code>import argparse
  import sys
  from Crypto.Hash import MD5, SHA1, SHA224, SHA256, SHA384, SHA512
  
  
  parser = argparse.ArgumentParser(description='Hash production')
  parser.add_argument('-v', action='store_true', dest='verbose', default=False, help='Print attempts')
  parser.add_argument('-t', nargs=1, dest='inputHashType', help='Hash type')
  parser.add_argument('-d', nargs='?', dest='wordlist', type=argparse.FileType('rt', encoding='utf-8'), default=sys.stdin, help='Dictionary (as file)')
  args =  parser.parse_args()
  
  inputHashType = ''.join(map(str, args.inputHashType)) # Formats args list as string
  inputHashType.lower()
  
  if inputHashType == 'md5':
      htype = MD5.new()
  
  try:
      if args.verbose:
          with args.wordlist as file:
              line = file.readline()
              cnt = 1
              while line:
                  word = line.encode('utf-8').rstrip()
                  hashed = htype.update(word)
                  hashed = htype.hexdigest()
                  print("Line {}:  PT: {}      As hash: {}".format(cnt, line.strip(), hashed))
                  line = file.readline()
                  cnt += 1
      else:
          break
  except:
      print('Error')
  </code></pre>