title: How to generate a password file to crack the zip file?
body: <p>I have an assignment regarding zip file password cracking by using python. It is not an unethical or illegal cracking project, it is an school assignment. I would like to ask how to generate passwords and test for cracking one by one? i.e. firstly generating a password '0' and then test ingit, if it is not successfully cracked, it then will generates second a password '1' and test it again.</p>
  
  <p>I had some code, but the problem is it only starts to crack the zip file after it generates a bunch of passwords. For example, I set it to generate starting from '0000' to '9999', when I run the code, it will generates all the passwords from '0000' to '9999', then it will just start to crack the zip file.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>import zipfile
  from datetime import datetime
  from itertools import product
  import itertools  
  
  
  str_09 = "0123456789"
  
  file_pwd = 'password/pwd-str_09-8.txt'
  mystring = str_09
  
  myfile = open(file_pwd, 'w')
  for a in range(1,6):
    for i in itertools.product(mystring, repeat=a):
      myfile.write("%s\n" % ''.join(map(str, i)))
  myfile.close()
  
  file_pwd = 'password/pwd-str_09-8.txt'
  zip_file_created_a = 'file/a5.zip'
  
  count = 1
  
  with open(file_pwd,'rb') as text:
          for entry in text.readlines():
              password = entry.strip()
              try:
                  with zipfile.ZipFile(zip_file_created_a,'r') as zf:
                      zf.extractall(pwd=password)
                      data = zf.namelist()[0]
                      data_size = zf.getinfo(data).file_size
                      print('''******************************\n[+] Password found! ~ %s\n ~%s\n ~%s\n******************************''' 
                          % (password.decode('utf8'), data, data_size))
                      break
  
              except:
                  number = count
                  print('[%s] [-] Password failed! - %s' % (number,password.decode('utf8')))
                  count += 1
                  pass
  
  
  </code></pre>