github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/brutecheck/twohashshifttablealt.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "sort" 6 ) 7 8 type TwoHashShiftTableAlt struct{} 9 10 func (TwoHashShiftTableAlt) Generate(p Printer, keywords []string) { 11 minlen, _ := keywordBounds(keywords) 12 if minlen < 2 { 13 return 14 } 15 16 for _, comb0 := range combiners { 17 for _, comb1 := range combiners { 18 for shiftn := byte(0); shiftn < 8; shiftn++ { 19 for shift0 := byte(0); shift0 < 8; shift0++ { 20 next: 21 for shift1 := byte(0); shift1 < 8; shift1++ { 22 var seen [256]bool 23 hashes := make([]byte, len(keywords)) 24 for i, keyword := range keywords { 25 h := twoHashCalcAlt(keyword, comb0, comb1, shiftn, shift0, shift1) 26 if seen[h] { 27 continue next 28 } 29 hashes[i] = h 30 seen[h] = true 31 } 32 33 sort.Sort(&sortByHash{keywords, hashes}) 34 35 fnname := fmt.Sprintf("TwoHashTableAlt_%s%s_Shift%d%d%d", comb0.Name, comb1.Name, shiftn, shift0, shift1) 36 p.FuncName(fnname) 37 p.F("func %s(name string) bool {\n", fnname) 38 p.F("if len(name) < 2 { return false }\n") 39 40 maxhash := hashes[len(hashes)-1] 41 p.F("h := %s\n", twoHashFormatAlt(comb0, comb1, shiftn, shift0, shift1)) 42 p.F("if h > %d { return false }\n", maxhash) 43 44 p.F("return [...]string{\n") 45 for i, keyword := range keywords { 46 p.F("%d: %q,\n", hashes[i], keyword) 47 } 48 p.F("}[h] == name\n") 49 //p.F("return names[h] == name\n") 50 51 p.F("}\n\n") 52 } 53 } 54 } 55 } 56 } 57 }