|
1 | 1 | import hashlib |
| 2 | + |
| 3 | + |
2 | 4 | def has(): |
3 | | - #List available algorithms |
| 5 | + # List available algorithms |
4 | 6 | print("Available algorithms are: ") |
5 | | - q=sorted(list(hashlib.algorithms_available)) |
| 7 | + q = sorted(list(hashlib.algorithms_available)) |
6 | 8 | for i in range(len(q)): |
7 | | - print('{0: <20}'.format(q[i]),end="") |
8 | | - if i%3==2: |
| 9 | + print('{0: <20}'.format(q[i]), end="") |
| 10 | + if i % 3 == 2: |
9 | 11 | print() |
10 | | - str2hash = list(input("Enter the names of the algorithms separated by space : ").split()) #Take input of algorithm names separated by space |
11 | | - stri=input("Enter the message: ") #Enter the message to be encoded |
| 12 | + # Take input of algorithm names separated by space |
| 13 | + str2hash = list(input("Enter the algorithms separated by space: ").split()) |
| 14 | + stri = input("Enter the message: ") # Enter the message to be encoded |
12 | 15 | for i in str2hash: |
13 | | - i=i.lower() |
14 | | - |
15 | | - if i in list(hashlib.algorithms_available): #check whether names provided by user is valid or not |
16 | | - result = hashlib.new(i) |
| 16 | + i = i.lower() |
| 17 | + # check whether names provided by user is valid or not |
| 18 | + if i in list(hashlib.algorithms_available): |
| 19 | + result = hashlib.new(i) |
17 | 20 | result.update(stri.encode()) |
18 | | - print("The hexadecimal equivalent of "+i+" hash is : ", end ="") |
| 21 | + print("The hexadecimal equivalent of "+i+" hash is : ", end="") |
19 | 22 | print(result.hexdigest()) |
20 | 23 | else: |
21 | 24 | print(i+" is not a valid algorithm name") |
22 | 25 |
|
23 | 26 |
|
24 | 27 | print("------Secure messages with hash--------") |
25 | 28 | has() |
26 | | -inp=input("Do you wish to continue?[y/n]") |
27 | | -while inp.lower()=='y': |
| 29 | +inp = input("Do you wish to continue?[y/n]") |
| 30 | +while inp.lower() == 'y': |
28 | 31 | has() |
29 | | - inp=input("Do you wish to continue?[y/n]") |
| 32 | + inp = input("Do you wish to continue?[y/n]") |
30 | 33 | print("Goodbye") |
31 | | - |
32 | | - |
33 | | - |
0 commit comments