-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
42 lines (33 loc) · 1.07 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"crypto/rand"
"encoding/base64"
"flag"
"fmt"
"strconv"
"github.com/bcext/cashutil/base58"
"github.com/qshuai/tcolor"
)
type encodeType string
const (
base58Encoding encodeType = "base58"
base64Encoding encodeType = "base64"
bytesLengthLimit = 500
defaultBytesLength = 60
)
func main() {
length := flag.Int("length", defaultBytesLength, "Please input the needed length of the generated random string (base58 encoded string length is not precision)")
encode := flag.String("encode", string(base64Encoding), "Please input encode type (base64 encoded string with character '+/=')")
flag.Parse()
if *length > bytesLengthLimit {
fmt.Println(tcolor.WithColor(tcolor.Yellow, "the input length too big. use default length: "+strconv.Itoa(defaultBytesLength)))
*length = defaultBytesLength
}
data := make([]byte, int(*length*3)/4)
rand.Read(data)
if *encode == string(base58Encoding) {
fmt.Println(tcolor.WithColor(tcolor.Green, base58.Encode(data)))
return
}
fmt.Println(tcolor.WithColor(tcolor.Green, base64.StdEncoding.EncodeToString(data)))
}