Hash functions are used in cryptography and other areas. These data structures are presented with code examples related to cryptography. There are two ways to implement a hash function in Go: with crc32 or sha256. Marshaling (changing the string to an encoded form) saves the internal state, which is used for other purposes later. A BinaryMarshaler (converting the string into binary form) example is explained in this section:
//main package has examples shown
// in Hands-On Data Structures and algorithms with Go book
package main
// importing bytes, crpto/sha256, encoding, fmt and log package
import (
"bytes"
"crypto/sha256"
"encoding"
"fmt"
"log"
"hash"
)
The main method creates a binary marshaled hash of two example strings. The hashes of the two strings are printed. The sum of the first hash is compared...