Compare commits

...

1 Commits

Author SHA1 Message Date
a81bebfaf8 More flexible letter/symbol/nunmber combinations. 2019-10-01 18:01:55 -04:00

20
main.go
View File

@ -6,10 +6,16 @@ import (
"math/big"
)
type Generator func() (byte,error)
var chars []byte = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~`!@#$%^&*()_+-=[]{}\\|;:'\",./<>?")
var letters []byte = chars[0:52]
var digits []byte = chars[52:62]
var letdig []byte = chars[0:62]
var symbols []byte = chars[62:94]
var digsym []byte = chars[52:94]
var letsym []byte = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@#$%^&*()_+-=[]{}\\|;:'\",./<>?")
func gen(s []byte) (byte,error) {
nBig, err := crand.Int(crand.Reader, big.NewInt(int64(len(s))))
@ -32,11 +38,23 @@ func Symbol() (byte,error) {
return gen(symbols)
}
func LetterDigits() (byte,error) {
return gen(letdig)
}
func DigitsSymbols() (byte,error) {
return gen(digsym)
}
func LettersSymbols() (byte, error) {
return gen(letsym)
}
func Char() (byte,error) {
return gen(chars)
}
func Slice(f func() (byte,error), n int) ([]byte,error) {
func Slice(f Generator, n int) ([]byte,error) {
ret := make([]byte,0)
for i := 0; i < n; i++ {
x,err := f()