func checksum(data []byte) string {
	fullHash := sha512.Sum512_256(data)
	temp := fullHash[0:2]
	chkBytes := toUint11Array(temp)
	return applyWords(chkBytes, wordlist)[0]
}
Checksum returns a word that represents the 11 bit checksum of the data
package mnemonic
import (
	"crypto/sha512"
	"fmt"
	"strings"
)
const (
	bitsPerWord      = 11
	checksumLenBits  = 11
	keyLenBytes      = 32
	mnemonicLenWords = 25
	paddingZeros     = bitsPerWord - ((keyLenBytes * 8) % bitsPerWord)
)
var sepStr = " "
var emptyByte = byte(0)
func init() {
	if mnemonicLenWords*bitsPerWord-checksumLenBits != keyLenBytes*8+paddingZeros {
		panic("cannot initialize passphrase library: invalid constants")
	}
}
func FromKey(key []byte) (string, error) {
	if len(key) != keyLenBytes {
		return "", errWrongKeyLen
	}
	chk := checksum(key)
	uint11Array := toUint11Array(key)
	words := applyWords(uint11Array, wordlist)
	return fmt.Sprintf("%s %s", strings.Join(words, " "), chk), nil
}
func ToKey(mnemonic string) ([]byte, error) {
	wordsRaw := strings.Split(mnemonic, sepStr)
	var words []string
	for _, word := range wordsRaw {
		if word != "" {
			words = append(words, word)
		}
	}
	if len(words) != mnemonicLenWords {
		return nil, errWrongMnemonicLen
	}
	for _, w := range words {
		if indexOf(wordlist, w) == -1 {
			return nil, fmt.Errorf("%s is not in the words list", w)
		}
	}
	var uint11Array []uint32
	for i := 0; i < len(words)-1; i++ {
		uint11Array = append(uint11Array, uint32(indexOf(wordlist, words[i])))
	}
	byteArr := toByteArray(uint11Array)
	if len(byteArr) != keyLenBytes+1 {
		return nil, errWrongKeyLen
	}
	if byteArr[keyLenBytes] != emptyByte {
		return nil, errWrongChecksum
	}
	byteArr = byteArr[0:keyLenBytes]
	mnemonicChecksum := checksum(byteArr)
	if mnemonicChecksum != words[len(words)-1] {
		return nil, errWrongChecksum
	}
	if len(byteArr) != keyLenBytes {
		panic("passphrase:MnemonicToKey is broken: recovered wrong amount of data")
	}
	return byteArr, nil
}
func toUint11Array(arr []byte) []uint32 {
	var buffer uint32
	var numberOfBit uint32
	var output []uint32
	for i := 0; i < len(arr); i++ {
		buffer |= uint32(arr[i]) << numberOfBit
		numberOfBit += 8
		if numberOfBit >= 11 {
			output = append(output, buffer&0x7ff)
			buffer = buffer >> 11
			numberOfBit -= 11
		}
	}
	if numberOfBit != 0 {
		output = append(output, buffer&0x7ff)
	}
	return output
}
func toByteArray(arr []uint32) []byte {
	var buffer uint32
	var numberOfBits uint32
	var output []byte
	for i := 0; i < len(arr); i++ {
		buffer |= uint32(arr[i]) << numberOfBits
		numberOfBits += 11
		for numberOfBits >= 8 {
			output = append(output, byte(buffer&0xff))
			buffer >>= 8
			numberOfBits -= 8
		}
	}
	if buffer != 0 {
		output = append(output, byte(buffer))
	}
	return output
}
func applyWords(arr []uint32, words []string) []string {
	res := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		res[i] = words[arr[i]]
	}
	return res
}
func indexOf(arr []string, s string) int {
	for i, w := range arr {
		if w == s {
			return i
		}
	}
	return -1
}