Briefly:
Message-digest algorithm 5 (Information-Digest algorithm). Often said "MD5 encryption", is it → information-digest algorithm.
MD5, in fact, is an algorithm. You can put a string, or a file, or a compressed package, after executing MD5, you can generate a fixed length of 128bit string. This string is basically the only one.
Irreversibility:
Everyone has a different fingerprint, see this person, can draw his fingerprints and other information, and the only correspondence, but you only look at a fingerprint, it is impossible to see or read the person's appearance or identity and other information.
Characteristics
- Compressibility: Any length of data, the calculated length of the MD5 value is fixed.
- Easy to calculate: It is easy to calculate the MD5 value from the original data.
- Anti-modification: Make any changes to the original data, even if only 1 bytes are modified, the resulting MD5 value is very different.
- Strong anti-collision: known raw data and its MD5 value, it is very difficult to find a data with the same MD5 value (that is, falsification of data).
MD5 length
The length of the MD5, which defaults to 128bit, is a binary string of 128 0 and 1. It is very unfriendly to say so. So the binary is turned into 16, each 4 bit represents a 16 binary, so 128/4 = 32 is 16 decimal after the 32 binary representation.
Why is there a 16-bit MD5 on the Internet?
In fact, the 16-bit length is from the 32-bit MD5 value. The 32-bit MD5 is removed from the first eight bits, and the last eight bits are removed.
Python Code implementation
The basic example:
1 #-*-coding:utf-8-*-2 #Coding=utf-83 ImportHashlib4 5 Print("Example One")6str ="This is a MD5 test"7 8H1 =hashlib.md5 ()9 TenH1.update (Str.encode (encoding='Utf-8')) One A Print("MD5 ency before:"+str) - Print("MD5 ency After:"+h1.hexdigest ()) - the - Print("Example") -str ="This is a MD5 testqqqqqqqqqqqqqqqqqqqqqqqaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa " - +H1 =hashlib.md5 () - +H1.update (Str.encode (encoding='Utf-8')) A atTop
View Code
Reference Document: Https://www.jianshu.com/p/4ba20afacce2
The concept principle of MD5 (Information Digest algorithm) and the implementation of Python code