-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
67 lines (56 loc) · 1.74 KB
/
main.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from sys import argv
from hashlib import md5, sha256, sha512
from datetime import datetime
import re
# python main.py md5 hash.txt dict.txt
hash_count, good, bad = 0, 0, 0
logname = datetime.now().strftime('%Y_%m_%d') + '.log'
try:
algrtm, hashfile, dictfile = argv[1], argv[2], argv[3]
except IndexError:
print('Invalid arguments')
raise SystemExit
def write_result(chash, cpass):
with open(logname, 'a') as result:
line = str(datetime.now().strftime('%Y-%m-%d %H:%M:%S')) + ' - ' + '[' + algrtm.upper() + '] ' + chash + ' - ' + cpass + '\n'
result.writelines(line)
def generator(string):
global good
status = '[Not Found]'
for word in string:
password = word.replace('\n', '')
if encryption(password) == workhash:
yield '[FIND]'
good += 1
status = password
break
# else:
# yield '[NO]' + password
print(workhash + ':' + status)
return write_result(workhash, status)
def encryption(string):
password = string.encode()
if algrtm == 'md5':
signature = md5(password).hexdigest()
elif algrtm == 'sha256':
signature = sha256(password).hexdigest()
elif algrtm == 'sha512':
signature = sha512(password).hexdigest()
else:
print(algrtm, '- is unknown algoritm.')
raise SystemExit
return signature
with open(hashfile) as file:
for workhash in file:
hash_count += 1
workhash = workhash.replace('\n', '').lower()
if re.match(r'^[0-9a-f]', workhash) is None: # r'^[0-9a-f]{32}$'
print(workhash + ':' + '[Invalid Hash]')
write_result(workhash, cpass='[INVALID HASH]')
bad += 1
else:
with open(dictfile, errors='ignore') as dic:
for line in generator(dic):
print(line)
print('[Hashes]', '\nTotal:\t', hash_count, '\nFinded:\t', good, '\nInvalid:', bad)
print('All detail results save into:', logname)