An algorithm (algorithm) is a set of well-defined rules used to solve a problem within a finite step. It can be said that the algorithm is the process of computer problem solving.
The algorithm has five important characteristics:
1. Poor sex: Limited steps
2. Clarity: Every step of the algorithm must have a definite meaning
3. Input: An algorithm has 0 or more inputs to characterize the initial situation of the operands, so-called 0 inputs are the initial conditions of the algorithm itself
4. Output: An algorithm has one or more outputs to reflect the results of processing the input data.
5. Feasibility: The algorithm can be run precisely in principle
Hash is an algorithm, the algorithm is like a factory, accept incoming content (input), after processing (operation) to get processed products (a string of hasn value).
Features of the hash algorithm:
1. As long as the incoming content, after the calculation of the resulting hash value must be the same; ===== Integrity verification
2.hash value can not be reversed; ======= the password into a hash value, not in the form of clear text transmission/storage
3. As long as the hash algorithm does not change, regardless of the content of the plaintext is mostly small, the length of the hash value is the same. = = = "Does not affect network transmission
Import hashlib# General Usage One # m=hashlib.md5 (' HelloWorld '. Encode (' Utf-8 ')) # Print (M.hexdigest ()) # fc5e038d38a57032085441e7fe7010b0# General Usage Two # M=HASHLIB.MD5 () # m.update (' Hello '. Encode (' Utf-8 ')) # m.update (' World '). Encode (' Utf-8 ') # Print (M.hexdigest ()) #fc5e038d38a57032085441e7fe7010b0 # M=HASHLIB.MD5 () # m.update (' HelloWorld '). Encode (' Utf-8 ') # Print (M.hexdigest ()) #fc5e038d38a57032085441e7fe7010b0 # M=HASHLIB.MD5 () # m.update (' Hello World '). Encode (' Utf-8 ') # Print (M.hexdigest ()) #5eb63bbbe01eeed093cb22bb8f5acdc3 ' ' from the exercises above, we can see that the same content gets the same hash value, a little bit of change, Even adding a space will get a different hash result.
Add salt
Import hashlibm=hashlib.md5 () m.update (' King of the Land Tiger '. Encode (' Utf-8 ')) m.update (' Password ... '. Encode (' Utf-8 ')) m.update (' chicken stew mushroom '. Encode (' Utf-8 ')) print (M.hexdigest ()) #6e7122afda007b679dfb7759f9122783
HMAC Module
Import hmach=hmac.new (' King cover the Tiger ' Encode (' Utf-8 ')) h.update (' Password ... '. Encode (' Utf-8 ')) print (H.hexdigest ()) #e76a9abfcec64c6594384c14dbbd8f82
Python's Hashlib module