SHA-3 implementation
Secure Hash Algorithm-3 additionally called Keccak, is a unidirectional method for creating computerized prints of the given length according to the standards as 224, 256, 384, or 512 pieces from input information of any size, created by a gathering of creators drove by Yoan Dimen in 2008 and embraced in 2015 as the new FIPS standard. The calculation works by methods for the blending capacity in with compression to the choose size “cryptographic sponge”.
Examples:
Input: HelloWorld
Output[sha3_224]: c4797897c58a0640df9c4e9a8f30570364d9ed8450c78ed155278ac0
Input: HelloWorld
Output[sha3_256]: 92dad9443e4dd6d70a7f11872101ebff87e21798e4fbb26fa4bf590eb440e71b
Input: HelloWorldOutput[sha3_384]: dc6104dc2caff3ce2ccecbc927463fc3241c8531901449f1b1f4787394c9b3aa55a9e201d0bb0b1b7d7f8892bc127216
Input: HelloWorld
Output[sha3_512]: 938315ec7b0e0bcac648ae6f732f67e00f9c6caa3991627953434a0769b0bbb15474a429177013ed8a7e48990887d1e19533687ed2183fd2b6054c2e8828ca1c
The following programs show the implementation of SHA-3 hash in Python-3.8 using different methods: Implementation of sha3_224 using the update method
Python3
import sys import hashlib if sys.version_info < ( 3 , 6 ): import sha3 # initiating the "s" object to use the # sha3_224 algorithm from the hashlib module. s = hashlib.sha3_224() # will output the name of the hashing algorithm currently in use. print (s.name) # will output the Digest-Size of the hashing algorithm being used. print (s.digest_size) # providing the input to the hashing algorithm. s.update(b "w3wiki" ) print (s.hexdigest()) |
sha3_224 28 11c044e8080ed87b3cf0643bc5880a38ae62dd4562390700000b1191
Implementation of sha3_256 using encode method
Python3
# import the library module import sys import hashlib if sys.version_info < ( 3 , 6 ): import sha3 # initialize a string str = "w3wiki" # encode the string encoded_str = str .encode() # create sha3-256 hash objects obj_sha3_256 = hashlib.sha3_256(encoded_str) # print in hexadecimal print ( "\nSHA3-256 Hash: " , obj_sha3_256.hexdigest()) |
Output:
SHA3-256 Hash: b05a48e99c60983b96b5a69efad8bb44e586702d484d43e592ab639ef64641ff
Implementation of sha3_384
Python3
# import the library module import sys import hashlib if sys.version_info < ( 3 , 6 ): import sha3 # initialize a string str = "w3wiki" # encode the string encoded_str = str .encode() # create sha3-384 hash objects obj_sha3_384 = hashlib.sha3_384(encoded_str) # print in hexadecimal print ( "\nSHA3-384 Hash: " , obj_sha3_384.hexdigest()) |
Output:
SHA3-384 Hash: b92ecaaafd00472daa6d619b68010b5f66da7c090e32bd4f5a6b60899e8de3e2c859792ec07a33775cfca8d05c64f222
Implementation of sha3_512 using the new method
Python3
import sys import hashlib if sys.version_info < ( 3 , 6 ): import sha3 str = "w3wiki" # create a sha3 hash object hash_sha3_512 = hashlib.new( "sha3_512" , str .encode()) print ( "\nSHA3-512 Hash: " , hash_sha3_512.hexdigest()) |
Output:
SHA3-512 Hash: 3706a96a8fa96b3fc5ff30cbca36ce666042e2d07762022a78a2ec82439848fc3695e83336ab71f47dddbc24b96454df2a437e343801a4e13faab89e8d0fda61
Applications of Hashing-Algorithms:
- Message Digest
- Password Verification
- Data Structures(Programming Languages)
- Compiler Operation
- Rabin-Karp Algorithm
- Linking File name and path together
SHA3 in Python
A cryptographic hash function is an exceptional class of hash function that has certain properties that make it appropriate for use in cryptography. It is a numerical algorithm that maps information of self-assertive size to a piece line of a fixed size (a hash function) which is intended to likewise be a one-way output function, that is, a function which is infeasible to revert.