Python Module--hashlib module (Simple File digest algorithm implementation)

Source: Internet
Author: User
Tags sha1 wrapper

#!/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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.