title: TypeError: must be string or buffer, not int
body: <p>i am trying to solve the <code>Rainbow Tables</code> issue with password encryption and have come only this far. </p>
  
  <pre><code>import sys
  import random
  import hashlib
  
  def mt_rand (low = 0, high = sys.maxint):
      """Generate a better random value
      """
      return random.randint (low, high)
  
  def substr (s, start, length = None):
      """Returns the portion of string specified by the start and length
      parameters.
      """
      if len(s) &gt;= start:
          return False
      if not length:
          return s[start:]
      elif length &gt; 0:
          return s[start:start + length]
      else:
          return s[start:length]
  
  def unique_salt():
      return substr(hashlib.sha1(mt_rand()),0,22)
  
  password = "12345"
  salt = unique_salt()
  hash = hashlib.sha1(salt + password).hexdigest()
  print(hash)
  </code></pre>
  
  <p>I am getting this error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:/Users/Ajay/PycharmProjects/itertools/test.py", line 27, in &lt;module&gt;
      salt = unique_salt()
    File "C:/Users/Ajay/PycharmProjects/itertools/test.py", line 24, in unique_salt
      return substr(hashlib.sha1(mt_rand()),0,22)
  TypeError: must be string or buffer, not int
  </code></pre>
  
  <p>I know i am missing something very trivial but cant get where i am missing.
  Please Help.</p>