You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
358 B

5 years ago
  1. package main
  2. import (
  3. "crypto/rand"
  4. "math/big"
  5. )
  6. func generateChallenge(length int) (string, error) {
  7. result := ""
  8. for {
  9. if len(result) >= length {
  10. return result, nil
  11. }
  12. num, err := rand.Int(rand.Reader, big.NewInt(int64(127)))
  13. if err != nil {
  14. return "", err
  15. }
  16. n := num.Int64()
  17. if n > 32 && n < 127 {
  18. result += string(n)
  19. }
  20. }
  21. }