Python和GO語言實現的訊息摘要演算法示例

2022-10-03 09:39:07 字數 1469 閱讀 3683

常用的訊息摘要演算法有md5和sha,這些演算法在python和go的庫中都有,需要時候呼叫下就ok了,這裡總結下python和go的實現。

一、python訊息摘要示例

**如下:

複製** **如下:

#! /usr/bin/python

'''      file      : testhash.py

author    : mike

e-mail    : [email protected]

'''import hashlib

src = raw_input("input string : ")

funcnamelist = ["md5","sha1","sha224","sha256","sha384","sha512"]

funcmap =

for funcname in funcnamelist :

print funcname,"\t:\t",funcmap[funcname](src)

執行效果:

二、go語言訊息摘要示例

**如下:

複製** **如下:

/*      file      : hashtest.go

author    : mike

e-mail    : [email protected]

*/package main

import (

"fmt"

"crypto/md5"

"crypto/sha1"

"crypto/sha256"

"crypto/sha512"

"hash"

)func main()

funcmap := map[string]func(msg byte) hash.hash,

"sha1"          :   func(msg byte) hash.hash,

"sha224"        :   func(msg ilgnnpzjpbyte) hash.hash,

"sha256"        :   func(msg byte) hash.hash,

"sha384"        :   func(msg byte) hash.hash,

"sha512"        :   func(msg byte) hash.hash,

}fmt.printf("input string : ")

var msg1 string

fmt.scanf("%s",&msg1)

for _,funcname := range funcnamelist

}執行效果:

哈哈,是不是發現上面兩組程式的**結構相同啊,其實我就是想借助python來學習go語言的:先用python很輕巧的實現乙個功能,我再考慮用go做一遍。這裡總結下,方便以後使用。

本文標題: python和go語言實現的訊息摘要演算法示例

本文位址:

Go語言實現Valid Parentheses

write a function called that takes a string of parentheses,and determines if the order of the parentheses is valid.the function should return true if ...

go語言實現檔案的讀寫和拷貝

package file utils import bufio fmt io io ioutil os 開啟檔案 func openfile filepath string else fmt.println file err file.close if err nil 普通方式讀取檔案 func r...

LRU演算法的GO語言實現

lru演算法原理,來自 1.假設我們使用雜湊鍊錶來快取使用者資訊,目前快取了4個使用者,這4個使用者是按照時間順序依次從鍊錶右端插入的 2.此時,業務方訪問使用者5,由於雜湊鍊錶中沒有使用者5的資料,我們從資料庫中讀取出來,插入到快取當中。這時候,鍊錶中最右端是最新訪問到的使用者5,最左端是最近最少...