The concept principle of MD5 (Information Digest algorithm) and the implementation of Python code

Source: Internet
Author: User
Tags md5 encryption

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
    1. Compressibility: Any length of data, the calculated length of the MD5 value is fixed.
    2. Easy to calculate: It is easy to calculate the MD5 value from the original data.
    3. Anti-modification: Make any changes to the original data, even if only 1 bytes are modified, the resulting MD5 value is very different.
    4. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.