In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Python how to carry out data fingerprint MD5 verification comparison, many novices are not very clear about this, in order to help you solve this problem, the following small series will explain in detail for everyone, there are people who need this can learn, I hope you can gain something.
Python3-Data Fingerprint MD5 Verification and Comparison
MD5 Message-Digest Algorithm is a widely used cryptographic hash function that produces a 128-bit (16-byte) hash value to ensure that the message is transmitted completely and consistently. MD5 was designed by American cryptographer Ronald Linn Rivest and published in 1992 to replace MD4.
overview
MD5 check code is calculated by hash function, which can generate data "fingerprint" of any data, that is, we can use MD5 to compress message or data into digest, so that the amount of data is small, so as to compare and verify the integrity and correctness of data. Because it is almost impossible for two different files to have the same MD5 hash value, any non-malicious change to a file will cause its MD5 hash value to change. MD5 hashes check file integrity, especially to detect file transfers, disk errors, or other conditions.
MD5
In Python we can use the built-in module hashlib to complete the implementation and use of MD5.
import hashlibm = hashlib.md5()#Assuming file contents src = 'I like Python's m.update(src.encode ('utf-8'))print(m.hexdigest())
Example results:
17008b7417701b0c233b999d20c13f1d
document verification
Suppose there are two files, and we need to verify that they are the same
import hashlibdef out_md5(src): #Simple package m = hashlib.md5() m.update(src.encode('utf-8')) return m.hexdigest()with open('1.txt', 'r') as f: src = f.read () m1 = out_md5(src) print(m1)with open('2.txt', 'r') as f: src = f.read() m2 = out_md5(src) print(m2)if m1 == m2: print (False)else: print(True)
Example results:
bb0c1b519a0a2b8e6c74703e44538c6043cb091db43a710d85ce45fb202438cdFalse Is it helpful to read the above? If you still want to have further understanding of related knowledge or read more related articles, please pay attention to the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.