Question: Given hash_function( ) defined in the default template, complete the main function that does the following tasks: Create a list called hash_list that contains the

Given hash_function( ) defined in the default template, complete the main function that does the following tasks:

Create a list called hash_list that contains the five hashing algorithm names described above.

Read from the user a password to hash.

Declare a salt variable and initialize the variable to the hex representation of 4458585599393. Hint: Use function hex().

Use a for loop to iterate over the hash_list and call the hash_function() with the hashing algorithm names in the list. Store the returned value of hash_function() in a variable and output the algorithm name used and the hashed password. Note: Output a new line after each hashed password is printed.

hash_function( ) takes three parameters: the password to be hashed, a salt containing the hex representation of a 13-digit number, and a hashing algorithm name. hash_function( ) applies a specific hashing algorithm to the combination of the password and the salt value. hash_function( ) then returns a text containing the hashed data in hex representation and the salt value.

Given hash_function( ) defined in the default template, complete the main function

my code is:

import hashlib

def hash_function(password, salt, al): if al == 'md5': #md5 hash = hashlib.md5(salt.encode() + password.encode()) hash.update(password.encode('utf-8')) return hash.hexdigest() + ':' + salt elif (al == 'sha1'): #sha1 hash = hashlib.sha1() hash.update(password.encode('utf-8')) return hash.hexdigest() + ':' + salt elif al == 'sha224': #sha224 hash = hashlib.sha224() hash.update(password.encode('utf-8')) return hash.hexdigest() + ':' + salt elif al == 'sha256': #sha256 hash = hashlib.sha256() hash.update(password.encode('utf-8')) return hash.hexdigest() + ':' + salt elif al == 'blake2b': #blake2b512 hash = hashlib.blake2b() hash.update(password.encode('utf-8')) return hash.hexdigest() + ':' + salt else: print("Error: No Algorithm!")

if __name__ == "__main__": hash_list = ['md5', 'shal', 'sha224', 'sha256', 'blake2b'] password = str(input()) salt = hex(78246391246824) for i in range (len(hash_list)): print("Testing hash algorithm: " + hash_list[i]) print("Hashed password = " + hash_function(password, salt, hash_list[i]) + " ")

I am getting this error:

Traceback (most recent call last): File "main.py", line 38, in print("Hashed password = " + hash_function(password, salt, hash_list[i]) + " ") TypeError: can only concatenate str (not "NoneType") to str

Ex: If the input is: secretpass the output is: Testing hash algorithm: md5 Hashed Password = bd19f99253c948637d64a4acbd524047:0x40e18692da1 Testing hash algorithm: shal Hashed Password = e5fbad38af8ba59c2648e98b9ae4196dfcb9f719:0x40e18692da1 Testing hash algorithm: sha224 Testing hash algorithm: sha256 Hashed Password = e73b86702464baa976c947a2a8c06adedc1e45ff5a35a07db 41385120ce1e10a:0x40e18692da1 Testing hash algorithm: blake2b Hashed Password = 386 eef23 64609396229c7b58f3606354c12224cecfbc97f7b435c83218 eee0b 93d453a8ffa1ca fcfcf 5452013bc671 fb 538

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!