hash function in python code example
Example 1: create function in python
def myFunction():
print('I am running in a function!')
Example 2: python hash function
import hashlib
str = "TYCS"
result = hashlib.sha1(str.encode())
print("The hexadecimal equivalent of SHA1 is : ")
print(result.hexdigest())
result = hashlib.sha224(str.encode())
print("The hexadecimal equivalent of SHA224 is : ")
print(result.hexdigest())
result = hashlib.sha256(str.encode())
print("The hexadecimal equivalent of SHA256 is : ")
print(result.hexdigest())
str = "TYCS"
result = hashlib.sha384(str.encode())
print("The hexadecimal equivalent of SHA384 is : ")
print(result.hexdigest())
str = "TYCS"
str = "TYCS"
result = hashlib.sha512(str.encode())
print("The hexadecimal equivalent of SHA512 is : ")
print(result.hexdigest())
Example 3: hash symbol in python
score=0
q1=(input("What is 1+1? : "))
if q1 == "2" :
print ("CORRECT")
score=(score+1)
else:
print ("INCORRECT")
q2=(input("""The capital city of England is...
a/Birmingham
b/London
c/Cardiff
Enter your answer: """))
if q2 == "b" :
print ("CORRECT")
score=(score+1)
else:
print ("INCORRECT")
q3=(input("7÷2="))
if q3 == "3.5":
print ("CORRECT")
score=(score+1)
else:
print ("INCORRECT")
print ("You got", score, "out of 3!!!")
Example 4: python hash
from hashlib import blake2b
import time
k = str(time.time()).encode('utf-8')
h = blake2b(key=k, digest_size=16)
h.hexdigest()
Example 5: hash table in python
dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
name = dict["Name"]
Example 6: hash in python
hash(object)