Advertisement
Mihai_Preda

Untitled

Jun 5th, 2021
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1. import os
  2. import zipfile
  3. import sys
  4. from random import randint
  5. from multiprocessing import Process
  6. import io
  7.  
  8.  
  9. class Decrypter:
  10.     LEN_MAX = 15
  11.  
  12.     def __init__(self, pr):
  13.         print(f"Process #{pr} started!")
  14.         with open("words.txt", "r") as fin:
  15.             self.words = fin.readlines()
  16.             self.words = [bytes(i[:-1], encoding='utf-8') for i in self.words]
  17.  
  18.         self.nr = len(self.words)
  19.  
  20.         with open("zip-test-55.zip", "rb") as zip:
  21.             zip_file = io.BytesIO(zip.read())
  22.         self.file = zipfile.ZipFile(zip_file)
  23.         self.bruteforce()
  24.  
  25.     def print_result(self, p):
  26.         ans = str(p, encoding='utf-8')
  27.         with open("password.txt", "w") as fout:
  28.             fout.write(ans)
  29.         sys.exit()
  30.  
  31.     def get_rnd(self):
  32.         return randint(0, self.nr - 1)
  33.  
  34.     def try_decrypt(self, passwd):
  35.         try:
  36.             self.file.extractall(pwd=passwd)
  37.             print("SUCCESS:", passwd)
  38.             self.print_result(passwd)
  39.             sys.exit()
  40.         except Exception as e:
  41.             pass
  42.  
  43.     def bruteforce(self):
  44.         while True:
  45.             taken = [False for i in range(self.nr)]
  46.             ans = b''
  47.             while (len(ans) < Decrypter.LEN_MAX):
  48.                 p = self.get_rnd()
  49.                 if taken[p]:
  50.                     continue
  51.                
  52.                 taken[p] = True
  53.                 ans += self.words[p]
  54.                 self.try_decrypt(ans)
  55.  
  56.  
  57. def main():
  58.     NR_PROCESS = 16
  59.     prc = []
  60.     for i in range(NR_PROCESS):
  61.         prc.append(Process(target=Decrypter, args=(i,)))
  62.         prc[-1].start()
  63.  
  64. if __name__ == "__main__":
  65.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement