-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash_cracker.py
60 lines (52 loc) · 1.95 KB
/
hash_cracker.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
'''importing required modules'''
import os
import hashlib
from base64 import b64decode
def hash_cracker():
'''function that cracks user hash using rockyou.txt'''
# check if rockyou.txt exists
if not os.path.exists('rockyou.txt'):
print('Error: rockyou.txt not found!\nMake sure to put it in the same directory')
return
# asking for algorithm
while True:
try:
print('0) Base64\n1) MD5\n2) SHA-256\n')
hash_type = int(input('Select algorithm: '))
if hash_type <= 3:
break
print('Error: Should be between 0 and 2.')
except ValueError:
print('Error: Not a valid number.')
match hash_type:
case 0:
print('Selected Base64.')
case 1:
print('Selected MD5.')
case 2:
print('Selected SHA-256.')
while True:
try:
user_hash = input('Enter hash: ')
if not user_hash:
raise ValueError('empty string')
break
except ValueError as e:
print(e)
match hash_type:
case 0:
print(f'Successfully Decoded! \n{user_hash}:{b64decode(user_hash).decode()}')
case 1:
with open(f'{os.getcwd()}/rockyou.txt', mode='r', encoding='utf-8') as wordlist:
for word in wordlist:
hex_result = hashlib.md5(word.encode('utf-8')).hexdigest()
if hex_result == user_hash:
print(f'Successfully cracked!\n{user_hash}:{word}')
break
case 2:
with open(f'{os.getcwd()}/rockyou.txt', mode='r', encoding='utf-8') as wordlist:
for word in wordlist:
hex_result = hashlib.sha256(word.encode('utf-8')).hexdigest()
if hex_result == user_hash:
print(f'Successfully cracked!\n{user_hash}:{word}')
break