Linux下计算md5sum,sha1sum,crc:

命令          输出

$md5sum hello    f19dd746bc6ab0f0155808c388be8ff0  hello

$sha1sum hello    79e560a607e3e6e9be2c09a06b7d5062cb5ed566  hello

$crc32 hello      327213a2

Python也能做这个工作,其中md5和sha1需import hashlib, crc32可以import zlib

#test.py
#!/usr/bin/env python

from hashlib import md5, sha1
from zlib import crc32
import sys def getMd5(filename): #计算md5
mdfive = md5()
with open(filename, 'rb') as f:
mdfive.update(f.read())
return mdfive.hexdigest() def getSha1(filename): #计算sha1
sha1Obj = sha1()
with open(filename, 'rb') as f:
sha1Obj.update(f.read())
return sha1Obj.hexdigest() def getCrc32(filename): #计算crc32
with open(filename, 'rb') as f:
return crc32(f.read()) if len(sys.argv) < 2:
print('You must enter the file')
exit(1)
elif len(sys.argv) > 2:
print('Only one file is permitted')
exit(1) filename = sys.argv[1] print('{:8} {}'.format('md5:', getMd5(filename)))
print('{:8} {}'.format('sha1:', getSha1(filename)))
print('{:8} {:x}'.format('crc32:', getCrc32(filename)))

$python test.py hello

结果:

md5: f19dd746bc6ab0f0155808c388be8ff0
sha1: 79e560a607e3e6e9be2c09a06b7d5062cb5ed566
crc32: 327213a2

最新文章

  1. 优化SQLServer--表和索引的分区(二)
  2. ASP.NET Web API 创建帮助页
  3. 【leetcode】Convert Sorted Array to Binary Search Tree
  4. PHP---------PHP函数里面的static静态变量
  5. Authentication和Authorization的区别
  6. 线程本地存储TLS(Thread Local Storage)的原理和实现&mdash;&mdash;分类和原理
  7. 如何设置DB2I(SPUFI)来正常工作
  8. 类名.class与类名.this详解
  9. Selenium 下载URL
  10. 纠错记录(Could not open the editor: Android XML Editor cannot process this input.)
  11. sn9c291 驱动载入成功,mpayer无法播放
  12. [翻译]高并发框架 LMAX Disruptor 介绍
  13. python学习:绝对路径和相对路径
  14. Flip Game---poj1753(状压+bfs)
  15. splice的多种用法
  16. 解决thinkphp设置session周期无效的问题
  17. 【websocket-sharp】使用
  18. asp.net部署时加密config文件
  19. Hibernate的调用数据库的存储过程
  20. LeetCode OJ:Rotate List(旋转链表)

热门文章

  1. 千万PV级别WEB站点架构设计
  2. 使用InternetReadFile时要注意读取完整数据
  3. 理解 Objective-C 的 ARC
  4. ural 1049. Brave Balloonists(标准分解式,数论)
  5. URLEncode和URLDecoder作用
  6. lua学习
  7. LeetCode OJ 26. Remove Duplicates from Sorted Array
  8. nefu 196 让气球飞吧
  9. php---数组序列化
  10. 天津工业大学CST专业培养方案