Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import zipfile
- import sys
- from random import randint, shuffle
- from multiprocessing import Process
- import io
- class Decrypter:
- LEN_MAX = 15
- def __init__(self, pr):
- print(f"Process #{pr} started!")
- with open("words.txt", "r") as fin:
- self.words = fin.readlines()
- self.words = [bytes(i[:-1], encoding='utf-8') for i in self.words]
- with open("words_class.txt", "r") as fin:
- self.words_class = fin.readlines()
- self.words_class = [int(i) for i in self.words_class]
- self.nr = len(self.words)
- with open("zip-test-55.zip", "rb") as zip:
- zip_file = io.BytesIO(zip.read())
- self.file = zipfile.ZipFile(zip_file)
- self.bruteforce()
- def print_result(self, p):
- ans = str(p, encoding='utf-8')
- with open("password.txt", "w") as fout:
- fout.write(ans)
- sys.exit()
- def try_decrypt(self, passwd):
- try:
- self.file.extractall(pwd=passwd)
- print("SUCCESS:", passwd)
- self.print_result(passwd)
- sys.exit()
- except Exception as e:
- pass
- def bruteforce(self):
- while True:
- taken = [False for i in range(self.words_class[-1] + 1)]
- ans = b''
- words_list = [i for i in range(0, self.nr-1)]
- shuffle(words_list)
- word_ind = 0
- while word_ind < self.nr and len(ans) < Decrypter.LEN_MAX:
- ans += self.words[words_list[word_ind]]
- self.try_decrypt(ans)
- taken[self.words_class[word_ind]] = True
- while taken[self.words_class[word_ind]]:
- word_ind += 1
- def main():
- NR_PROCESS = 16
- prc = []
- for i in range(NR_PROCESS):
- prc.append(Process(target=Decrypter, args=(i,)))
- prc[-1].start()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement