Python hashlib – SHA3 hash generator

In this post we will be creating a Python script that will generate SHA3 hash strings using the hashlib library. The hashlib library will allow us to easily generate secure cryptographic hash functions. People commonly use these hash functions to store passwords, verify data integrity, and perform other cryptographic applications. The library offers a wide range of available hash functions which make it a valuable tool for any developer seeking to implement strong security measures.

In this example we will be generating a SHA3 hash which stands for Secure Hash Algorithm 3. This hash function generates a fixed-size output of various lengths, including 224, 256, 384, and 512 bits. It is designed to enhance security and protect against different types of attacks.

See the snippet of Python code where we use the hashlib library to generate a SHA3 hash string. The script utilizes a while loop where the user can enter a string to hash and the hash will be returned to output.

import hashlib

while True:
    string = input("Enter string to hash: ")
    sha3_hash = hashlib.sha3_256(string.encode()).hexdigest()
    print("SHA3 hash is", sha3_hash)

See some example output below.

Enter string to hash: password123
SHA3 hash is ab3fe4003f14e3ef573417f95e47d4985c482eadd139c08b3758eeae7cc60b9d

Enter string to hash: computer786
SHA3 hash is 7637c7141bb319235a81f118dd7e57285e99da80f2adf6b13f134f72a649cedb

Take a look at some of our other content around the Python programming language by clicking here.

Leave a Reply