I was thinking about this topic a couple of months ago, my problem was to write a encrypt and decrypt-function. The thing was I want that my collegues sent me a 4 sign PIN and when would get a activate key from me to can activae the my program.
(defun encrypt (str / p)
(setq p (mapcar '+ (vl-string->list str) '(1 8 14 19 3 6 17 36 25 4 1 9 62)))
(princ (strcat "\n The activate key is: " (vl-list->string p)))
(princ)
)
(defun decrypt (str / p)
(setq p (vl-list->string (mapcar '- (vl-string->list str) '(1 8 14 19 3 6 17 36 25 4 1 9 62))))
)
(defun c:GetAPassword (/ key)
(if (and (setq password (getstring "\n Type a 4 sign PIN! "))
(setq key (strcat password (rtos (getvar "cdate") 2 0)))
)
(encrypt key)
)
(princ)
)
(defun c:ActivatePassWord (/ fname file)
(if (eq (decrypt (getstring "\n Type in Activate key! "))
(strcat (if (null password)
(progn
(princ "\n Password is expiered\n")
(exit)
)
password
)
(rtos (getvar "cdate") 2 0)
)
)
(progn
(princ "\n Program is activated! ")
(vl-registry-write "HKEY_CURRENT_USER\\Test" "" password)
(setq fname (strcat "C:\\Temp\\Test\\password" ".txt")) ; here it saved your password
(if (setq file (open fname "w"))
(write-line password file)
)
(close file)
)
(princ "\n Password i wrong! ")
)
(setq password nil)
(princ)
)
(defun c:foo ( / fname file)
(if (= (if (setq fname (strcat "C:\\Temp\\Test\\password" ".txt"))
(if (not (setq file (open fname "r")))
(princ "\n You have no password ")
(read-line file)
)
)
(if (not (vl-registry-read "HKEY_CURRENT_USER\\Test"))
(princ "\n You have no PIN")
(vl-registry-read "HKEY_CURRENT_USER\\Test")
)
)
(alert " Program is starting ")
(alert "\n No license! ")
)
(princ)
)
I´m not proffs, I think your password-generator looks fine here. Are you thinking as same way when I to activate a program ?