The commonly used message digest algorithms are MD5 and SHA, which are available in both Python and go libraries, and are OK when called, which summarizes the implementation of Python and went.
Example of a Python message digest
The code is as follows:
Copy Code code as follows:
#! /usr/bin/python
'''
File:testHash.py
Author:mike
E-mail:mike_zhang@live.com
'''
Import Hashlib
src = 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)
Operation Effect:
Two, go Language message Digest sample
The code is as follows:
Copy Code code 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 (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},
"SHA224": Func (msg []byte) hash. Hash{var h Hash. Hash = sha256. New224 (); 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:")
var MSG1 string
Fmt. SCANF ("%s", &MSG1)
For _,funcname: = Range funcnamelist{
Fmt. Printf ("%s \t:\t%x\n", Funcname,funcmap[funcname] ([]byte (MSG1)). Sum ())
}
}
Operation Effect:
Haha, is not found in the above two groups of code structure of the same ah, in fact, I just want to use Python to learn the go language: first with Python is very lightweight to achieve a function, I will consider using go to do again. Here is a summary, convenient to use later.