File_Blast.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from unrar import rarfile#需要安装unrar和一个windows的插件
  2. import itertools
  3. def make_pwd(min,max,word = '123456789'):
  4. while min <= max:
  5. iter = itertools.product(word,repeat=min)
  6. for i in iter:
  7. yield ''.join(i)#生成器,join生成str
  8. min += 1
  9. def Un_RAR(pwd,out_path,file):
  10. try:
  11. file.extractall(out_path, pwd=pwd)
  12. return True
  13. except:#密码错误
  14. return False
  15. def make_file(file_path,out_path):
  16. file = rarfile.RarFile(file_path)
  17. return file,file_path,out_path
  18. def start_(min,max,word):
  19. print('Start to run...')
  20. for pwd in make_pwd(min,max,word):
  21. if Un_RAR(pwd,out_put_file_path,file):
  22. print(f'Password is {pwd}')
  23. break
  24. else:
  25. print(f"isn't {pwd}" )
  26. if __name__ == '__main__':
  27. file,file_path,out_put_file_path = make_file(r"xxx",r'yyy')#创建文件xxx为压缩包位置,yyy为输出位置
  28. inf = float("inf")#无穷
  29. min = 4
  30. max = 4
  31. word = r'''1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'''
  32. start_(min,max,word)