Created
November 23, 2013 09:51
-
-
Save pnathan/7612750 to your computer and use it in GitHub Desktop.
Calculate the keyspace of a password.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun keyspace (string) | |
"Calculates the keyspace of an ASCII string; this can be used to | |
deny certain passwords from being used." | |
;; Hopefully the implementation is a smart string and knows how long | |
;; it is automatically. | |
(let ((length (length string)) | |
(capabilities (make-hash-table :test #'eq))) | |
;; O(n) | |
(loop for ele across string | |
do | |
(cond | |
((upper-case-p ele) | |
(setf (gethash :upper-case capabilities) 26)) | |
((lower-case-p ele) | |
(setf (gethash :lower-case capabilities) 26)) | |
((digit-char-p ele) | |
(setf (gethash :digit capabilities) 10)) | |
(t | |
(setf (gethash :other capabilities) 33)))) | |
;; O(n) | |
(expt (loop for value being the hash-values of capabilities | |
sum value) | |
length))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment