March 2019
Intermediate to advanced
336 pages
9h 9m
English
Hash functions were introduced in Chapter 4, Non-Linear Data Structures. Hash implementation in Go has crc32 and sha256 implementations. An implementation of a hashing algorithm with multiple values using an XOR transformation is shown in the following code snippet. The CreateHash function takes a byte array, byteStr, as a parameter and returns the sha256 checksum of the byte array:
//main package has examples shown// in Go Data Structures and algorithms bookpackage main// importing fmt packageimport ( "fmt" "crypto/sha1" "hash")//CreateHash methodfunc CreateHash(byteStr []byte) []byte { var hashVal hash.Hash hashVal = sha1.New() hashVal.Write(byteStr) var bytes []byte bytes = hashVal.Sum(nil) return bytes}
In the following sections, ...
Read now
Unlock full access