github.com/pkumar631/talisman@v0.3.2/detector/hex_detector.go (about) 1 package detector 2 3 const HEX_CHARS = "1234567890abcdefABCDEF" 4 const HEX_ENTROPY_THRESHOLD = 2.7 5 const MIN_HEX_SECRET_LENGTH = 20 6 7 type HexDetector struct { 8 hexMap map[string]bool 9 entropy *Entropy 10 } 11 12 func NewHexDetector() *HexDetector { 13 bd := HexDetector{} 14 bd.initHexMap() 15 bd.entropy = &Entropy{} 16 return &bd 17 } 18 19 func (hd *HexDetector) initHexMap() { 20 hd.hexMap = map[string]bool{} 21 for i := 0; i < len(HEX_CHARS); i++ { 22 hd.hexMap[string(HEX_CHARS[i])] = true 23 } 24 } 25 26 func (hd *HexDetector) checkHexEncoding(word string) string { 27 entropyCandidates := hd.entropy.GetEntropyCandidatesWithinWord(word, MIN_HEX_SECRET_LENGTH, hd.hexMap) 28 for _, candidate := range entropyCandidates { 29 entropy := hd.entropy.GetShannonEntropy(candidate, HEX_CHARS) 30 if entropy > HEX_ENTROPY_THRESHOLD { 31 return word 32 } 33 } 34 return "" 35 }