To hash a string using a custom hash function in Go, you can follow these steps:
func customHash(str string) int {
hash := 0
for _, character := range str {
hash += int(character)
}
return hash
}
stringToHash := "Hello, World!"
hashValue := customHash(stringToHash)
The hashValue
variable will store the hash value of the given string.
Note that this is a simple and straightforward hash function implementation for demonstration purposes. In practice, you may want to use more complex and secure hash functions like SHA256 or bcrypt for stronger security.