diff --git a/7/shumilova_sd/cracking.py b/7/shumilova_sd/cracking.py new file mode 100644 index 00000000..9bdd5a9b --- /dev/null +++ b/7/shumilova_sd/cracking.py @@ -0,0 +1,53 @@ +from hashlib import sha384 +from string import printable + +def hash(password): + return sha384(password.encode()).hexdigest() + +dict = printable[:95] + +def first_letter(n, d): + return dict[n * d:(n + 1) * d] + +def next_word(lst: list): + length = len(lst) + if length == 1 and lst[0] == 94: + return None + if lst[0] != 94: + lst[0] += 1 + return lst + else: + i = 1 + while lst[i] == 94 and i <= length - 2: + i += 1 + if i == length - 1 and lst[i] == 94: + return None + lst[i] += 1 + for j in range(i): + lst[j] = 0 + return lst + +def crack(hash_input, n, d, flag): + length = 1 + for password_word in first_letter(n, d): + if hash_input == hash(password_word): + print(f'I know your password, and it is: "{password_word}"') + flag.value = 1 + break + + while not flag.value: + word_list = [0] * length + length += 1 + r = 0 + while word_list is not None: + password_word = ''.join(dict[i] for i in word_list) + for i in first_letter(n, d): + if hash(i + password_word) == hash_input: + print(f'I know your password, and it is: "{i + password_word}".') + flag.value = 1 + break + word_list = next_word(word_list) + r += 1 + if r % 100000 == 0: + if flag.value == 1: + break \ No newline at end of file diff --git a/7/shumilova_sd/hashing.py b/7/shumilova_sd/hashing.py new file mode 100644 index 00000000..89733dca --- /dev/null +++ b/7/shumilova_sd/hashing.py @@ -0,0 +1,7 @@ +from cracking import hash + +print('Пароль должен содержать не более 4-х символов. Может состоять из латинских букв, цифр и/или специальных символов.') +password = input('Please, enter your password: ') + +with open('password.txt', 'w') as file: + file.write(hash(password)) diff --git a/7/shumilova_sd/main.py b/7/shumilova_sd/main.py new file mode 100644 index 00000000..64cc41a1 --- /dev/null +++ b/7/shumilova_sd/main.py @@ -0,0 +1,21 @@ +import sys +from cracking import crack, dict +from multiprocessing import cpu_count, Process, Value + +if __name__ == '__main__': + length = len(dict) + c = cpu_count() + password = open('password.txt').read() + flag = Value('i', 0) + processes = [] + for i in range(c): + d = int(length/c) + 1 + p = Process(target=crack, args=(password, i, d, flag)) + processes.append(p) + processes[-1].start() + flag = True + while flag: + for p in processes: + if not (p.is_alive()): + f = False + sys.exit() diff --git a/README.md b/README.md deleted file mode 100644 index 792bbd3c..00000000 --- a/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# 🐍, 2 семестр -(как и в прошлом семестре) -Схема хранения файлов: номер\_задания / фамилия\_ио / файлы. -Если файл в задании один, можно директорию не создавать. -Предлагаю в именах файлов не использовать кириллицу. -Если деанонимизация тяготит, допускаю (но не приветствую) использование псевдонима.