Skip to content

Instantly share code, notes, and snippets.

@jjhop
Created November 2, 2018 17:10
Show Gist options
  • Save jjhop/3d71d6726872d816dc1f2576ff642c7d to your computer and use it in GitHub Desktop.
Save jjhop/3d71d6726872d816dc1f2576ff642c7d to your computer and use it in GitHub Desktop.
(cl:defpackage jjhop.util
(:export generate-password))
(defparameter *chars* '("a" "b" "c" "d" "e" "f" "g" "h" "i" "j"
"k" "m" "n" "o" "p" "q" "r" "s" "t" "u"
"v" "w" "x" "y" "z" "A" "B" "C" "D" "E"
"F" "G" "H" "J" "K" "L" "M" "N" "P" "Q"
"R" "S" "T" "U" "V" "W" "X" "Y" "Z" "2"
"3" "4" "5" "6" "7" "8" "9" "@" "#" "$"))
(defparameter *chars-length* (length *chars*))
(defparameter *rs* (make-random-state t))
(defun range (start end)
(if (> start end)
nil
(cons start (range (+ start 1) end))))
(defun flip-char (i)
(let ((r (random *chars-length* *rs*)))
(nth r *chars*)))
(defun generate-password (length)
(let* ((a (range 1 length))
(b (mapcar #'flip-char a)))
(format nil "~{~A~}" b)))
;; (write-line (generate-password 24))
;; (write-line (generate-password 128))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment