genpass-monkey 755 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env zsh
  2. #
  3. # Usage: genpass-monkey [NUM]
  4. #
  5. # Generate a password made of 26 alphanumeric characters
  6. # with the security margin of at least 128 bits.
  7. #
  8. # Example password: nz5ej2kypkvcw0rn5cvhs6qxtm
  9. #
  10. # If given a numerical argument, generate that many passwords.
  11. emulate -L zsh -o no_unset -o warn_create_global -o warn_nested_var
  12. if [[ ARGC -gt 1 || ${1-1} != ${~:-<1-$((16#7FFFFFFF))>} ]]; then
  13. print -ru2 -- "usage: $0 [NUM]"
  14. return 1
  15. fi
  16. zmodload zsh/system || return
  17. {
  18. local -r chars=abcdefghjkmnpqrstvwxyz0123456789
  19. local c
  20. repeat ${1-1}; do
  21. repeat 26; do
  22. sysread -s1 c || return
  23. # There is uniform because $#chars divides 256.
  24. print -rn -- $chars[#c%$#chars+1]
  25. done
  26. print
  27. done
  28. } </dev/urandom