-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4_hashing.py
36 lines (27 loc) · 1011 Bytes
/
4_hashing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
### HASHING ###
from helpers import mainnet,testnet
from pprint import pprint
# Hash functions takes data and gives you a fingerprint.You CANT reverse it
# This is a built in library in python
# To get more information on hashlib: help(hashlib)
import hashlib
# hashlib onjects return a hash obj
msg = b'hello, i am efe'
hash1 = hashlib.sha256(msg)
print(hash1,'\n')
# with digest we get the data in that hash object
hash2 = hashlib.sha256(msg).digest()
print(hash2,'\n')
# with hexdigest we get the hexadecimal data in that hash object
# Hexadecimal(means 16) characters: 0123456789ABCDEF
hash3 = hashlib.sha256(msg).hexdigest()
print(hash3,'\n')
# Example
# Get a string, turn it into bytes and hash it.
msg2 = input('Enter a string:')
print(msg2.encode()) #turns into byte
#You must change msg to the bytes with encode befre hashing
#hash5 = hashlib.sha256(msg2).hexdigest() #fail.
#print(hash5)
hash4 = hashlib.sha256(msg2.encode()).hexdigest() #get the hash with encoded string
print(hash4)