Common Message SummaryAlgorithmYesMD5AndShaThese algorithms arePythonAndGoIn the library,CallOKNow, here is a summaryPythonAndGo.
I,PythonMessage Digest example
CodeAs follows:
#! /Usr/bin/Python ''' File: testhash. py Author: Mike E-mail: Mike_Zhang@live.com ''' ImportHashlib Src =Raw_input("Input string :") Funcnamelist = ["MD5","Sha1","Shares","Sha256","Sha384","Sha512"] Funcmap = { "MD5":LambdaCNT: hashlib. MD5 (CNT). hexdigest (), "Sha1":LambdaCNT: hashlib. sha1 (CNT). hexdigest (), "Shares":LambdaCNT: hashlib. shaloud (CNT). hexdigest (), "Sha256":LambdaCNT: hashlib. sha256 (CNT). hexdigest (), "Sha384":LambdaCNT: hashlib. sha384 (CNT). hexdigest (), "Sha512":LambdaCNT: hashlib. sha512 (CNT). hexdigest () } ForFuncnameInFuncnamelist: PrintFuncname,"\ T:\ T", Funcmap [funcname] (SRC)
Running effect:
II,GoLanguage message digest example
The Code is as follows:
/* File: hashtest. Go Author: Mike E-mail: Mike_Zhang@live.com */ PackageMain Import( "FMT" "Crypto/MD5" "Crypto/sha1" "Crypto/sha256" "Crypto/sha512" "Hash" ) FuncMain (){ Funcnamelist: = [] String { "MD5" , "Sha1" , "Shares" , "Sha256" , "Sha384" , "Sha512" } funcmap: = Map [ string ] func (MSG [] byte ) hash. hash { " MD5 " : func (MSG [] byte ) hash. hash { var H hash. hash = md5.new (); H. write (MSG); return H }, " sha1 " : func (MSG [] byte ) hash. hash { var H hash. hash = sha1.new (); H. write (MSG); return H }, " shares' " : func (MSG [] byte ) hash. hash { var H hash. hash = sha256.newiterator (); H. write (MSG); return H }, " sha256 " : func (MSG [] byte ) hash. hash { var H hash. hash = sha256.new (); H. write (MSG); return H }, " sha384 " : func (MSG [] byte ) hash. hash { var H hash. hash = sha512.new384 (); H. write (MSG); return H }, " sha512 " : func (MSG [] byte ) hash. hash { var H hash. hash = sha512.new (); H. write (MSG); return H }, } FMT. printf ("Input string :") VaRMsg1String FMT. scanf ("% S", & Msg1) For_, Funcname: =RangeFuncnamelist { FMT. printf ( " % S \ t : \ t % x \ n " , funcname, funcmap [funcname] ([] byte (msg1 )). sum () } }
Running effect:
Haha, did you find the above two groups?ProgramThe code structure is the same.PythonTo learnGoLanguage: First UsePythonIt is very lightweight to implement a function. I will try againGoDo it again. It is summarized here for future use.