package engine import "math" // Shannon computes the Shannon entropy of a string in bits per character. // Returns 0.0 for empty strings. // A value >= 3.5 indicates high randomness, consistent with real API keys. func Shannon(s string) float64 { if len(s) == 0 { return 0.0 } freq := make(map[rune]float64) for _, c := range s { freq[c]++ } n := float64(len([]rune(s))) var entropy float64 for _, count := range freq { p := count / n entropy -= p * math.Log2(p) } return entropy }