forked from gil9red/SimplePyScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsingle.py
More file actions
40 lines (27 loc) · 1.07 KB
/
Copy pathsingle.py
File metadata and controls
40 lines (27 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = "ipetrash"
# SOURCE: https://ru.stackoverflow.com/a/776780/201445
import hashlib
from itertools import product
def brute_force(mask, hsh, alphabet):
# заменяем '*' на '{}' для последующей подстановки в 'str.format()'
pwd_pat = mask.replace("*", "{}")
# число звездочек - будем использовать в качестве `product(.., repeat)`
N = mask.count("*")
i = 0
for chars in product(alphabet, repeat=N):
i += 1
if i % 10000 == 0:
print(f"Iterations: {i}")
if hsh == hashlib.sha256(pwd_pat.format(*chars).encode()).hexdigest():
text = pwd_pat.format(*chars)
print(f"Found: {text}")
return text
return None
if __name__ == "__main__":
from string import ascii_letters, digits
alphabet = ascii_letters + digits
# Password: qwe12y
hsh = "b8cc184b3f4aeb6adb6601ea3e39ef5ac098791acc2a505a66746f43d0c7ed85"
print(brute_force("qw****", hsh, alphabet))