-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrainbow.py
68 lines (57 loc) · 2.02 KB
/
rainbow.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
import hashlib
import pyfiglet
def hash_sha256(password):
pass_hash = hashlib.sha256(f"{password}".encode('utf-8'))
hashed = pass_hash.hexdigest()
return hashed
def reduce_hash(hash, password_length):
return hash[:password_length]
def generate_chain(password, chain_length, password_length):
hash = hash_sha256(password)
for _ in range(chain_length):
password = reduce_hash(hash, password_length)
hash = hash_sha256(password)
return hash
def generate_rainbow_table_from_dictionary(dictionary):
rainbow_table = {}
chain_length = 1000
password_length = 8
for password in dictionary:
hash = generate_chain(password, chain_length, password_length)
rainbow_table[hash] = password
return rainbow_table
def load_dictionary(file_path):
with open(file_path, 'r') as file:
dictionary = file.read().splitlines()
return dictionary
def hash_to_password(hash, rainbow_table):
chain_length = 1000
for _ in range(chain_length):
hash = reduce_hash(hash, 8)
hash = hash_sha256(hash)
return rainbow_table[hash]
def main():
dictionary = load_dictionary('my_dict.txt')
rainbow_table = generate_rainbow_table_from_dictionary(dictionary)
# test
user_input = input("Enter a Password or Hash : ")
if len(user_input) == 64:
try:
password = hash_to_password(user_input, rainbow_table)
if hash_sha256(password) == user_input:
print("password is : "+password)
else:
print("Password not found")
except KeyError:
print("Password not found")
else:
hash = generate_chain(user_input, 1000, 8)
print("Hash is : "+hash)
try:
print("Password trouve dans la table : "+rainbow_table[hash])
except KeyError:
print("Password not found")
if __name__ == '__main__':
ascii_banner = pyfiglet.figlet_format("LaZa \n RAINBOW Attack simulator")
print(ascii_banner)
main()