Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Sonmur new #97

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions 7/shumilova_sd/cracking.py
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions 7/shumilova_sd/hashing.py
Original file line number Diff line number Diff line change
@@ -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))
21 changes: 21 additions & 0 deletions 7/shumilova_sd/main.py
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 0 additions & 6 deletions README.md

This file was deleted.