一个很简单的MD5计算,python hashlib

 1 import hashlib
 2 import time
 3 
 4 size = 2048
 5 md5 = hashlib.md5()
 6 start = time.time()
 7 with open('ubuntu-18.04-desktop-amd64.iso', 'rb') as f:
 8     a = f.read(2048)
 9     md5.update(a)
10     while len(a) > 0:
11         # print(a)
12         a = f.read(2048)
13         md5.update(a)
14         large = len(a)+large
15 end = time.time()
16 print('md5: %s:' %md5.hexdigest())
17 print('该文件大小: %sKb:' % size/1024)
18 print('所用的时间:%s:' % end - start)

猜你喜欢

转载自www.cnblogs.com/anc7/p/10009231.html