常用的消息摘要算法有MD5和SHA,这些算法在python和go的库中都有,需要时候调用下就OK了,这里总结下python和go的实现。
一、python消息摘要示例
代码如下:
#! /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)
运行效果:
二、go语言消息摘要示例
代码如下:
/*
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())
}
}
运行效果:
哈哈,是不是发现上面两组程序的代码结构相同啊,其实我就是想借助python来学习go语言的:先用python很轻巧的实现一个功能,我再考虑用go做一遍。这里总结下,方便以后使用。

Arraysinpython, terutamanya yang, arecrucialinscientificificputingputingfortheirefficiencyandversatility.1) mereka yang digunakan untuk

Anda boleh menguruskan versi python yang berbeza dengan menggunakan Pyenv, Venv dan Anaconda. 1) Gunakan pyenv untuk menguruskan pelbagai versi python: Pasang pyenv, tetapkan versi global dan tempatan. 2) Gunakan VENV untuk mewujudkan persekitaran maya untuk mengasingkan kebergantungan projek. 3) Gunakan Anaconda untuk menguruskan versi python dalam projek sains data anda. 4) Simpan sistem python untuk tugas peringkat sistem. Melalui alat dan strategi ini, anda dapat menguruskan versi Python yang berbeza untuk memastikan projek yang lancar.

Numpyarrayshaveseveraladvantagesoverstanderardpythonarrays: 1) thearemuchfasterduetoc-assedimplementation, 2) thearemorememory-efficient, antyedlargedataSets, and3) theyofferoptimized, vectorizedfuncionsformathhematicalicalicalicialisation

Kesan homogenitas tatasusunan pada prestasi adalah dwi: 1) homogenitas membolehkan pengkompil untuk mengoptimumkan akses memori dan meningkatkan prestasi; 2) tetapi mengehadkan kepelbagaian jenis, yang boleh menyebabkan ketidakcekapan. Singkatnya, memilih struktur data yang betul adalah penting.

ToCraftExecutablePythonscripts, ikutiTheseBestPractics: 1) addAshebangline (#!/Usr/bin/envpython3) tomakethescriptexecutable.2) setpermissionswithchmod xyour_script.py.3)

Numpyarraysarebetterfornumericationsoperationsandmulti-dimensialdata, whiletheArrayModuleissuitiableforbasic, ingatan-efisienArrays.1) numpyexcelsinperformanceandfunctionalityforlargedatasetsandcomplexoperations.2) thearrayModeMoremoremory-efficientModeMoremoremoremory-efficientModeMoremoremoremory-efficenceismemoremoremoremoremoremoremoremory-efficenceismemoremoremoremoremorem

NumpyarraysareBetterforheavynumericalcomputing, whilethearraymoduleismoresuitifFormemory-constrainedprojectswithsimpledatypes.1) numpyarraysofferversativilityandperformanceForlargedATAsetSandcomplexoperations.2)

ctypesallowscreatingandmanipulatingc-stylearraysinpython.1) usectypestointerwithclibrariesforperformance.2) createec-stylearraysfornumericalcomputations.3) Passarraystocfuntionsforficientsoperations.however, becautiousofmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmemmem


Alat AI Hot

Undresser.AI Undress
Apl berkuasa AI untuk mencipta foto bogel yang realistik

AI Clothes Remover
Alat AI dalam talian untuk mengeluarkan pakaian daripada foto.

Undress AI Tool
Gambar buka pakaian secara percuma

Clothoff.io
Penyingkiran pakaian AI

Video Face Swap
Tukar muka dalam mana-mana video dengan mudah menggunakan alat tukar muka AI percuma kami!

Artikel Panas

Alat panas

ZendStudio 13.5.1 Mac
Persekitaran pembangunan bersepadu PHP yang berkuasa

MantisBT
Mantis ialah alat pengesan kecacatan berasaskan web yang mudah digunakan yang direka untuk membantu dalam pengesanan kecacatan produk. Ia memerlukan PHP, MySQL dan pelayan web. Lihat perkhidmatan demo dan pengehosan kami.

SublimeText3 versi Cina
Versi Cina, sangat mudah digunakan

EditPlus versi Cina retak
Saiz kecil, penyerlahan sintaks, tidak menyokong fungsi gesaan kod

Muat turun versi mac editor Atom
Editor sumber terbuka yang paling popular
