The hashing function
Hashing is a function that takes an input of any length and turns it into a fixed-length output. To make this clearer, we can look at the following code example:
>>> import hashlib >>> hashlib.sha256(b"hello").hexdigest() '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824' >>> hashlib.sha256(b"a").hexdigest() 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb' >>> hashlib.sha256(b"hellohellohellohello").hexdigest() '25b0b104a66b6a2ad14f899d190b043e45442d29a3c4ce71da2547e37adc68a9'
As you can see, the length of the input can be 1
, 5
, or even 20
characters, but the output will always be the length of 64 hexadecimal numeric characters. The output looks scrambled, and there is no apparent link between the input and the output. However, if you give the same input, it will give the same output every time:
>>> hashlib.sha256(b...