github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/brutecheck/twohashshift.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "sort" 6 ) 7 8 type TwoHashShift struct{} 9 10 func (TwoHashShift) 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 := twoHashCalc(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("TwoHash_%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 p.F("switch %s {\n", twoHashFormat(comb0, comb1, shiftn, shift0, shift1)) 41 for i, keyword := range keywords { 42 p.F("case %d: return name == %q\n", hashes[i], keyword) 43 } 44 p.F("}\n") 45 } 46 p.F("return false\n") 47 p.F("}\n\n") 48 } 49 } 50 } 51 } 52 } 53 }