-
Notifications
You must be signed in to change notification settings - Fork 0
/
sha3.py
80 lines (68 loc) · 3.14 KB
/
sha3.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
import hashlib #importing the library
def sha3_256(str):
message=hashlib.sha3_256(str.encode()) #encoding
return message.hexdigest() #result in hexadecimal
def sha3_224(str):
message=hashlib.sha3_224(str.encode()) #encoding
return message.hexdigest() #result in hexadecimal format
def sha3_384(str):
message=hashlib.sha3_384(str.encode()) #encoding
return message.hexdigest() #result in hexadecimal format
def sha3_512(str):
message=hashlib.sha3_512(str.encode()) #encoding
return message.hexdigest() #result in hexadecimal format
def main():
message = input ("\nWhat do you want to hash?: \n")
decision=input("Select which instance of SHA-3 do you want to use:\n 1. SHA3-224 \n 2. SHA3-256 \n 3. SHA3-384\n 4. SHA3-512. \n")
if (decision=="1"):
output = sha3_224(message) #calling function, result calculation
print('Selected SHA3-224. Your coded message is: \n' + str(output)) #printing coded output
main()
elif (decision == "2"):
output = sha3_256(message) #calling function, result calculation
print("Selected SHA3-256. Your coded message is: \n" +str(output)) #printing coded output
main()
elif (decision =="3"):
output = sha3_384(message)
print("Selected SHA3-384. Your coded message is: \n" +str(output))
main()
elif(decision == "4"):
output = sha3_512(message)
print("Selected SHA3-512. Your coded message is: \n" +str(output))
main()
else:
print("You may enter only 1, 2, 3 or 4! ")
main()
main()
import hashlib #importing the library
def sha3_256(str):
message=hashlib.sha3_256(str.encode()) #encoding
return message.hexdigest() #result in hexadecimal
def sha3_224(str):
message=hashlib.sha3_224(str.encode()) #encoding
return message.hexdigest() #result in hexadecimal format
def sha3_384(str):
message=hashlib.sha3_384(str.encode()) #encoding
return message.hexdigest() #result in hexadecimal format
def sha3_512(str):
message=hashlib.sha3_512(str.encode()) #encoding
return message.hexdigest() #result in hexadecimal format
def main():
message = input ("What do you want to hash?: \n")
decision=input("Select which instance of SHA-3 do you want to use:\n 1. SHA3-224 \n 2. SHA3-256 \n 3. SHA3-384\n 4. SHA3-512. \n")
if (decision=="1"):
output = sha3_224(message) #calling function, result calculation
print('Selected SHA3-224. Your coded message is: \n' + str(output)) #printing coded output
elif (decision == "2"):
output = sha3_256(message) #calling function, result calculation
print("Selected SHA3-256. Your coded message is: \n" +str(output)) #printing coded output
elif (decision =="3"):
output = sha3_384(message)
print("Selected SHA3-384. Your coded message is: \n" +str(output))
elif(decision == "4"):
output = sha3_512(message)
print("Selected SHA3-512. Your coded message is: \n" +str(output))
else:
print("You may enter only 1, 2, 3 or 4! ") #just tin case
main()
main()