Files
identicon-algorithms/utils.go

27 lines
481 B
Go
Raw Normal View History

2026-02-28 16:36:53 +01:00
package main
import (
"crypto/sha1"
"fmt"
"strconv"
)
func rgbFromHex(hex string) (int, int, int) {
r, _ := strconv.ParseUint(hex[0:2], 16, 8)
g, _ := strconv.ParseUint(hex[2:4], 16, 8)
b, _ := strconv.ParseUint(hex[4:6], 16, 8)
return int(r), int(g), int(b)
}
func hash(str string) string {
h := sha1.New()
h.Write([]byte(str))
res := h.Sum(nil)
return fmt.Sprintf("%x", res)
}
func hasBit(n uint64, pos int) bool {
val := n & (1 << pos)
return (val > 0)
}