More flexible letter/symbol/nunmber combinations.
This commit is contained in:
parent
b6d598696c
commit
a81bebfaf8
20
main.go
20
main.go
|
@ -6,10 +6,16 @@ import (
|
||||||
"math/big"
|
"math/big"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Generator func() (byte,error)
|
||||||
|
|
||||||
|
|
||||||
var chars []byte = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~`!@#$%^&*()_+-=[]{}\\|;:'\",./<>?")
|
var chars []byte = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~`!@#$%^&*()_+-=[]{}\\|;:'\",./<>?")
|
||||||
var letters []byte = chars[0:52]
|
var letters []byte = chars[0:52]
|
||||||
var digits []byte = chars[52:62]
|
var digits []byte = chars[52:62]
|
||||||
|
var letdig []byte = chars[0:62]
|
||||||
var symbols []byte = chars[62:94]
|
var symbols []byte = chars[62:94]
|
||||||
|
var digsym []byte = chars[52:94]
|
||||||
|
var letsym []byte = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@#$%^&*()_+-=[]{}\\|;:'\",./<>?")
|
||||||
|
|
||||||
func gen(s []byte) (byte,error) {
|
func gen(s []byte) (byte,error) {
|
||||||
nBig, err := crand.Int(crand.Reader, big.NewInt(int64(len(s))))
|
nBig, err := crand.Int(crand.Reader, big.NewInt(int64(len(s))))
|
||||||
|
@ -32,11 +38,23 @@ func Symbol() (byte,error) {
|
||||||
return gen(symbols)
|
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) {
|
func Char() (byte,error) {
|
||||||
return gen(chars)
|
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)
|
ret := make([]byte,0)
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
x,err := f()
|
x,err := f()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user