github.com/devops-filetransfer/sshego@v7.0.4+incompatible/dict/pass.go (about) 1 package dict 2 3 import ( 4 cryrand "crypto/rand" 5 "encoding/binary" 6 "fmt" 7 ) 8 9 // Use crypto/rand to get an random int64 10 func cryptoRandInt64() int64 { 11 c := 8 12 b := make([]byte, c) 13 _, err := cryrand.Read(b) 14 if err != nil { 15 panic(err) 16 } 17 r := int64(binary.LittleEndian.Uint64(b)) 18 return r 19 } 20 21 func abs(x int64) int64 { 22 if x < 0 { 23 return -x 24 } 25 return x 26 } 27 28 func GetNewPasswordStarter() string { 29 na := int64(len(Adjectives)) 30 np := int64(len(ProperNames)) 31 nv := int64(len(Verbs)) 32 a := abs(cryptoRandInt64()) % na 33 p := abs(cryptoRandInt64()) % np 34 v := abs(cryptoRandInt64()) % nv 35 36 // total possible: 392761350; 28.5 bits 37 // fmt.Printf("total possible: %v\n", na*np*nv) 38 39 return fmt.Sprintf("%s %s %s", 40 Adjectives[a], 41 ProperNames[p], 42 Verbs[v]) 43 }