#!/usr/bin/env python#-*-coding:utf-8-*-__author__="Loki"#usage:hashlib ModuleImportHashlibImport Time#wrapper function Calc Length and use timedefLen_type_tools (res):defWrapper (*args, * *Kwargs): Cur_time=time.time () len_res= Len (res (*args, * *Kwargs)) Result= Res (*args, * *Kwargs) End_time= Time.time ()-Cur_timePrint('Primary HASH result length is {0}, use time {1:.2f}'. Format (len_res, end_time))returnresultreturnwrapperdefmenu_list (): Func_list= {} forIteminchHashlib.__dict__: ifSTR (item). StartsWith ("sha")orSTR (item). StartsWith ("MD5"): Func_list[item]= Hashlib.__dict__[item]returnFunc_list@len_type_toolsdefALGOL (data, num):ifNum! = 1: User_choose= Menu_list () [data[1]] () user_choose.update (Data[0].encode ("Utf-8")) returnuser_choose.hexdigest () user_choose= Menu_list () ["MD5"] () user_choose.update (Data[0].encode ("Utf-8")) returnuser_choose.hexdigest ()deffile_read (PATH): With open (R"{}". Format (path),'RB') as File_info:file_bin=File_info.read ()returnFile_bindefMain ():""".:: Hashlib Small tools::. By:loki 2018-06-25 Format: >> <file_path> [ALGOL] ALGOL:MD5 (default) SHA1 sha224 sha256 sha384 sha512 Example: >> c:\\test.txt sha1:return hash_value""" Print(Main.__doc__) File_path= Input ('>>'). Strip () File_path=file_path.split () argument_num=Len (file_path)Print(Algol (File_path, argument_num))if __name__=='__main__': Main () Time.sleep (15)
Summary:
Again this hashlib module learns, by the way reviews the lower adorner. Also used the next Magic method __dict__ function
Python Module--hashlib module (Simple File digest algorithm implementation)