Advertisement
Mihai_Preda

Untitled

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