title: Slow brute force program in python
body: <p>So here's the problem, our security teacher made a site that requires authentification and then asks for a code (4 characters) so that you can access to a file. He told us to write a brute force program in Python (any library we want) that can find the password. So to do that I wanted first to make a program that can try random combinations on that code field just to have an idea about the time of each request ( I'm using requests library) and the result was disapointing each request takes around 8 secs.
  With some calculations: 4^36=13 436 928 possible combination that would take my program around 155.52 days.
  I would really apreciate if any one can help me out to make that faster. ( he told us that it is possible to make around 1200 combinations per sec)</p>
  
  <p>Here's my code:</p>
  
  <pre><code>import requests
  import time
  import random
  
  def gen():
      alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"
      pw_length = 4
      mypw = ""
  
      for i in range(pw_length):
          next_index = random.randrange(len(alphabet))
          mypw = mypw + alphabet[next_index]
  
      return mypw
  
  t0 = time.clock()
  t1 = time.time()
  
  cookie = {'ig': 'b0b5294376ef12a219147211fc33d7bb'}
  
  for i in range(0,5):
      t2 = time.clock()
      t3 = time.time()
      values = {'RECALL':gen()}
      r = requests.post('http://www.example.com/verif.php', stream=True, cookies=cookie, data=values)
      print("##################################")
      print("cpu time for req ",i,":", time.clock()-t2)
      print("wall time for req ",i,":", time.time()-t3)
  
  print("##################################")
  print("##################################")
  print("Total cpu time:", time.clock()-t0)
  print("Total wall time:", time.time()-t1)
  </code></pre>
  
  <p>Thank you</p>