Skip to content

Instantly share code, notes, and snippets.

@zuf
Created January 19, 2017 22:06
Show Gist options
  • Save zuf/222e84597641ff8c1885777d8302aa05 to your computer and use it in GitHub Desktop.
Save zuf/222e84597641ff8c1885777d8302aa05 to your computer and use it in GitHub Desktop.
CLI tool which generates random strings (passwords) encoded with base58
package main
import "fmt"
import "flag"
import "crypto/rand"
import "math/big"
import "github.com/tv42/base58"
func secure_random(n int) []byte{
b := make([]byte, n)
_, err := rand.Read(b)
if err != nil {
fmt.Println("error:", err)
panic(fmt.Sprintf("Can't generate rangom bytes:", err))
}
return b
}
func main() {
n := flag.Int("n", 16, "random bytes per string")
c := flag.Int("c", 1, "generate given number of random strings")
flag.Parse()
var x big.Int
for i := 0; i < *c; i++ {
buf := base58.EncodeBig(nil, x.SetBytes(secure_random(*n)))
fmt.Printf("%s\n", buf)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment