python: 实现sha1小工具
2016-05-07 14:35
399 查看
File1: sha1.py
File2: sha1.bat
------------------
File2: sha1.bat
------------------
File1: sha1.py
import hashlib import os,sys def CalcSha1(filepath): with open(filepath,'rb') as f: sha1obj = hashlib.sha1(); print '>', while(True): data = f.read(20971520) #20M print '.', if (data == ''): break sha1obj.update(data) hash = sha1obj.hexdigest() print ' END' return hash.upper() if __name__ == "__main__": if len(sys.argv)!=2 : print("Usage: \n\tsha1 filename ") exit(1) hashfile = sys.argv[1] if not os.path.exists(hashfile): hashfile = os.path.join(os.path.dirname(__file__),hashfile) if not os.path.exists(hashfile): print("cannot found file") exit(1) sha1 = CalcSha1(hashfile) print 'SHA1: ', sha1
File2: sha1.bat
@python %~dp0sha1.py %*
相关文章推荐
- Python之解析json
- python中的有序字典
- Python的学习笔记(五)(简单的爬虫)
- python练习二—画幅好画
- python write( )函数
- python练习一—文本转化渲染为html
- Python之解析XML
- 111. Minimum Depth of Binary Tree [easy] (Python)
- Python: 删除已安装的模块或包 及 python工具pip的安装和使用
- python导入网址,采集网页内容
- 104. Maximum Depth of Binary Tree [easy] (Python)
- python生成指定文件名的txt文件
- python 多线程 threading (三)
- Python 简单斐波那契数列
- Python-opencv之目标定位
- Python数据分析示例(2)Day3
- pwntools使用简介
- python基础(三元运算+深浅拷贝+函数参数)
- python 多线程 thread 加锁(二)
- Detecting Insults in Social Commentary 数据分析报告(python)