-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhashing.py
213 lines (180 loc) · 6.51 KB
/
hashing.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import hashlib
import base64
import main
import sqlite3 as sql
conn = sql.connect('hash_db.db')
c = conn.cursor()
def register_word(x):
# MD5 crypt and add to hashs bank
list_word_type = [x.rstrip("\n"), "md5"]
c.execute("select * from hashs where plane=? and type=?;", list_word_type)
line = c.fetchone()
if line is not None:
plane = x.rstrip('\n')
else:
plane = x.rstrip('\n')
hash_hex = md5_encrypt(x.rstrip('\n'), 'hex')
hash_b64 = md5_encrypt(x.rstrip('\n'), 'base64')
hash_type = 'md5'
list_hashs = [plane, hash_hex, hash_b64, hash_type]
c.execute("insert into hashs(plane,hash_hex,hash_b64,type) values(?,?,?,?);", list_hashs)
conn.commit()
# SHA1 crypt and add to hashs bank
list_word_type = [x.rstrip("\n"), "sha1"]
c.execute("select * from hashs where plane=? and type=?;", list_word_type)
line = c.fetchone()
if line is not None:
plane = x.rstrip('\n')
else:
plane = x.rstrip('\n')
plane = x.rstrip('\n')
hash_hex = sha1_encrypt(x.rstrip('\n'), 'hex')
hash_b64 = sha1_encrypt(x.rstrip('\n'), 'base64')
hash_type = 'sha1'
list_hashs = [plane, hash_hex, hash_b64, hash_type]
c.execute("insert into hashs(plane,hash_hex,hash_b64,type) values(?,?,?,?);", list_hashs)
conn.commit()
# SHA256 crypt and add to hashs bank
list_word_type = [x.rstrip("\n"), "sha256"]
c.execute("select * from hashs where plane=? and type=?;", list_word_type)
line = c.fetchone()
if line is not None:
plane = x.rstrip('\n')
else:
plane = x.rstrip('\n')
hash_hex = sha256_encrypt(x.rstrip('\n'), 'hex')
hash_b64 = sha256_encrypt(x.rstrip('\n'), 'base64')
hash_type = 'sha256'
list_hashs = [plane, hash_hex, hash_b64, hash_type]
c.execute("insert into hashs(plane,hash_hex,hash_b64,type) values(?,?,?,?);", list_hashs)
conn.commit()
# SHA512 crypt and add to hashs bank
list_word_type = [x.rstrip("\n"), "sha512"]
c.execute("select * from hashs where plane=? and type=?;", list_word_type)
line = c.fetchone()
if line is not None:
plane = x.rstrip('\n')
else:
plane = x.rstrip('\n')
hash_hex = sha512_encrypt(x.rstrip('\n'), 'hex')
hash_b64 = sha512_encrypt(x.rstrip('\n'), 'base64')
hash_type = 'sha512'
list_hashs = [plane, hash_hex, hash_b64, hash_type]
c.execute("insert into hashs(plane,hash_hex,hash_b64,type) values(?,?,?,?);", list_hashs)
conn.commit()
def hash_analyser():
return 1
def md5_encrypt(message, type):
if type == 'hex':
result = hashlib.md5(message.encode()).hexdigest()
return result
elif type == 'base64':
result = hashlib.md5(message.encode()).hexdigest()
result = base64.b64encode(bytes.fromhex(result))
final = str(result)[2:len(result) + 2:1]
return final
def sha256_encrypt(message, type):
if type == 'hex':
result = hashlib.sha256(message.encode()).hexdigest()
return result
elif type == 'base64':
result = hashlib.sha256(message.encode()).hexdigest()
result = base64.b64encode(bytes.fromhex(result))[2:]
final = str(result)[2:len(result) + 2:1]
return final
def sha512_encrypt(message, type):
if type == 'hex':
result = hashlib.sha512(message.encode()).hexdigest()
return result
elif type == 'base64':
result = hashlib.sha512(message.encode()).hexdigest()
result = base64.b64encode(bytes.fromhex(result))
final = str(result)[2:len(result) + 2:1]
return final
def sha1_encrypt(message, type):
if type == 'hex':
result = hashlib.sha1(message.encode()).hexdigest()
return result
elif type == 'base64':
result = hashlib.sha1(message.encode()).hexdigest()
result = base64.b64encode(bytes.fromhex(result))
final = str(result)[2:len(result) + 2:1]
return final
def md5_enc():
msg = input("type a message to be encryped: ")
# printing original string
print("The original string is : " + str(msg))
# printing result
print("The string after hashing : ")
print("hex: ")
print(md5_encrypt(msg, 'hex'))
print("base64: ")
print(md5_encrypt(msg, 'base64'))
register_word(msg)
hashing()
def sha1_enc():
msg = input("type a message to be encryped: ")
# printing original string
print("The original string is : " + str(msg))
# printing result
print("The string after hashing : ")
print("hex: ")
print(sha1_encrypt(msg, 'hex'))
print("base64: ")
print(sha1_encrypt(msg, 'base64'))
register_word(msg)
hashing()
def sha256_enc():
msg = input("type a message to be encryped: ")
# printing original string
print("The original string is : " + str(msg))
# printing result
print("The string after hashing : ")
print("hex: ")
print(sha256_encrypt(msg, 'hex'))
print("base64: ")
print(sha256_encrypt(msg, 'base64'))
register_word(msg)
hashing()
def sha512_enc():
msg = input("type a message to be encryped: ")
# printing original string
print("The original string is : " + str(msg))
# printing result
print("The string after hashing : ")
print("hex: ")
print(sha512_encrypt(msg, 'hex'))
print("base64: ")
print(sha512_encrypt(msg, 'base64'))
register_word(msg)
hashing()
def hashing():
print("1: md5 ")
print("2: sh1 ")
print("3: sh256 ")
print("4: sh512 ")
print("5: Return ")
while True:
choix_1_1 = int(input("please type your choice : "))
try:
if choix_1_1 in [1, 2, 3, 4, 5]:
if choix_1_1 == 1:
md5_enc()
break
if choix_1_1 == 2:
sha1_enc()
break
if choix_1_1 == 3:
sha256_enc()
break
if choix_1_1 == 4:
sha512_enc()
break
elif choix_1_1 == 5:
main.menu()
break
else:
print("Please provide integer between 1 and 5")
except ValueError:
print("Please provide integer")
break