This is a creation in Article, where the information may have evolved or changed.
the common Message digest algorithm has MD5 and the SHA , these algorithms are python and the Go in the library, it takes time to invoke the next OK , summed up here python and the Go the implementation.
Example of aPython message digest
The code is as follows:
#!/usr/bin/python'''File:testHash.py Author:mike e-mail:mike_zhang@live.com ''' Import hashlibsrc = raw_input("input string:")funcnamelist = ["MD5","SHA1","SHA224","SHA256","SHA384" ,"SHA512"]Funcmap = { "MD5" : Lambda cnt:hashlib.md5 (CNT). Hexdigest (), "SHA1" : Lambda cnt:hashlib.sha1 (CNT). Hexdigest (), "SHA224" : Lambda cnt:hashlib.sha224 (CNT). Hexdigest (), "SHA256" : Lambda cnt:hashlib.sha256 (CNT). Hexdigest (), "SHA384" : Lambda cnt:hashlib.sha384 (CNT). Hexdigest (), "SHA512" : Lambda cnt:hashlib.sha512 (CNT). Hexdigest ()}For funcName in funcnamelist: Print funcName,"\ t:\ t", Funcmap[funcname] (SRC)
Operating effect:
Two,go language message Digest Example
The code is as follows:
/*File:hashTest.go Author:mike e-mail:mike_zhang@live.com */Package main Import ("FMT" "CRYPTO/MD5" "CRYPTO/SHA1" "crypto/sha256" "crypto/sha512" "Hash" ) func Main () { funcnamelist: = []string{"MD5","SHA1","SHA224","SHA256","SHA384","SHA512"} funcmap: = map [ string " func (msg [] byte ) hash. hash{ "MD5" :
func
byte ) hash. hash{ var h hash. Hash = MD5. New (); H.write (msg); return H}, "SHA1" :
func
byte ) hash. hash{ var h hash. Hash = SHA1. New (); H.write (msg); return H}, "SHA224" :
func
byte ) hash. hash{ var h hash. Hash = sha256. New224 (); H.write (msg); return H}, "SHA256" :
func
byte ) hash. hash{ var h hash. Hash = sha256. New (); H.write (msg); return H}, "SHA384" :
func
byte ) hash. hash{ var h hash. Hash = sha512. New384 (); H.write (msg); return H}, "SHA512" :
func
byte ) hash. hash{ var h hash. Hash = sha512. New (); H.write (msg); return H}, } FMT. Printf ("Input string:") var msg1 string FMT. SCANF ("%s", &MSG1) For _,funcname: = range funcnamelist{ fmt. Printf ( "%s \t : \t %x \n " ,funcname,funcmap[funcname] ([] byte } }
Operating effect:
Haha, is not found above two groups of code structure of the program is the same ah, in fact, I just want to use python to learn the go language: first with Python is a very lightweight implementation of a function, I would consider using go Do it again. Summarized here, convenient for later use.