TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Mark on August 29, 2013, 11:15:56 AM

Title: (Challenge) Password Generator
Post by: Mark on August 29, 2013, 11:15:56 AM
Using the language of your choice, create a password generator with at least one argument. The argument could be number of characters for example.

We have one here (http://www.theswamp.org/pwds.php) for example.


Good luck and have fun! :)
Title: Re: (Challenge) Password Generator
Post by: CAB on August 29, 2013, 11:28:00 AM
I've notice that many require passwords to be a minimum length, at least one number, one capital & one lower case letter and some require a "special character".
So I can't use my password 4321.  >:D
Title: Re: (Challenge) Password Generator
Post by: andrew_nao on August 29, 2013, 12:09:35 PM
I've notice that many require passwords to be a minimum length, at least one number, one capital & one lower case letter and some require a "special character".
So I can't use my password 4321.  >:D

thats the kind of combo you see on luggage  :lmao:
Title: Re: (Challenge) Password Generator
Post by: Vaidas on August 29, 2013, 12:42:34 PM
U53 L337 $P34|< Ph0R p455\/\/0RD :)
Title: Re: (Challenge) Password Generator
Post by: JohnK on August 29, 2013, 01:48:56 PM
Source code attached for a C++ CMake based project using a shared lib (dll).
Title: Re: (Challenge) Password Generator
Post by: Stefan on August 29, 2013, 03:25:29 PM
6 to 10 digits
Argument: 0, 1 or 2 for easy, medium or hard password (as in OP sample)
Code - Auto/Visual Lisp: [Select]
  1. (defun password (x / l n r)
  2.   (if
  3.     (vl-position x '(0 1 2))
  4.     (progn
  5.       (setq l (nth x '((48 49 50 51 52 53 54 55 56 57 97 98 99 100 101 102 103 104 105
  6.                         106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122)
  7.                        (48 49 50 51 52 53 54 55 56 57 65 66 67 68 69 70 71 72 73 74 75 76 77
  8.                         78 79 80 81 82 83 84 85 86 87 88 89 90 97 98 99 100 101 102 103 104
  9.                         105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122)
  10.                        (33 35 36 37 38 39 40 41 42 43 44 45 46 48 49 50 51 52 53 54 55 56
  11.                         57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
  12.                         81 82 83 84 85 86 87 88 89 90 91 93 94 95 96 97 98 99 100 101 102 103
  13.                         104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126))
  14.               )
  15.             n (length l)
  16.             )
  17.       (repeat (+ 6 (rem (dos_random) 5))
  18.         (setq r (cons (nth (rem (dos_random) n) l) r))
  19.         )
  20.       (vl-list->string r)
  21.       )
  22.      (not (princ "\nInvalid argument.\n0 - easy\n1 - medium\n2 - hard\n"))
  23.     )
  24.   )
Title: Re: (Challenge) Password Generator
Post by: Vaidas on August 29, 2013, 04:41:16 PM
Code: [Select]
; n - number of chars
; d - divisor
(defun kx:pwd (n d / p r)
 (setq p "")
 (repeat n
  (setq p (strcat p (chr (setq r (+ 33 (fix (* 0.94 (atoi (substr (rtos (getvar "date") 2 8) 15)))))))))
  (vl-cmdf "_delay" (/ r d))
 )
 p
)

; example:
(repeat 8
 (terpri)
 (princ (kx:pwd 8 4))
)

; or with random divisor:
(defun rnd ()
 (1+ (atoi (substr (rtos (getvar "date") 2 8) 16)))
)

(repeat 8
 (terpri)
 (princ (kx:pwd 8 (rnd)))
)
Title: Re: (Challenge) Password Generator
Post by: JohnK on August 29, 2013, 06:11:21 PM
This was a lot of fun Mark!! :D

I have been playing around with this challenge on and off. In the attached zip I have given the source and executable. What I have done since the above version was to start using the "Mersenne Twister" random number generator and also built a testing app. The testing app showed me that I needed to play with the "SEED" a little more (basically, wait for a bit then generate a new random number to get better/more random results). So I also started to use a higher precision timer class to give me a better/faster SEED calculator.

-e.g.
Code - C++: [Select]
  1. ...
  2. while(seed == oldSeed) {
  3.     t2 = pctimer();
  4.     seed = t1+t2;
  5. }

The attached version generates a new random number for every character in the string now (waits a long time). :)

Anyways, fun challenge.
Title: Re: (Challenge) Password Generator
Post by: Kerry on August 29, 2013, 06:40:54 PM
Hack ...

Code - Python: [Select]
  1. __codehimbelonga__ = 'KDUB'
  2.  
  3. import random
  4. import string
  5.  
  6.  
  7. def passGen(code_len=8):
  8.     seed = string.ascii_letters + string.punctuation + string.digits
  9.     return ''.join(random.sample(seed * code_len, code_len))
  10.  
  11.  
  12.  

Code - Python: [Select]
  1. print(passGen())
  2.  
  3. print(passGen(4))
  4.  
  5. print(passGen(9))
  6.  
  7. print(passGen(15))
  8.  
  9. print(passGen(25))
  10.  

Code - Python: [Select]
  1. #C:\Python33\python.exe "D:/_Python Source/theSwamp/PasswordGen.py"
  2. '8I.Ap$~
  3. zR&^
  4. Hx4Uuuzgf
  5. C3T%jez'"~~.hNU
  6. RL:nTEKiMGUM$Ng6Pbq&gc3Lk
  7.  

Good fun!!
Title: Re: (Challenge) Password Generator
Post by: Kerry on August 29, 2013, 06:58:54 PM
more Hack.
optional to add punctuation : 1 = add , 0 = remove

Code - Python: [Select]
  1. __codehimbelonga__ = 'KDUB'
  2.  
  3. import random
  4. import string
  5.  
  6.  
  7. def passGen(code_len=8, punct=1):
  8.     if punct == 1:
  9.         seed = string.ascii_letters + string.punctuation + string.digits
  10.     else:
  11.         seed = string.ascii_letters + string.digits
  12.     return ''.join(random.sample(seed * code_len, code_len))
  13.  

Code - Python: [Select]
  1. print(passGen())
  2.  
  3. print(passGen(4))
  4.  
  5. print(passGen(10))
  6. print(passGen(10, 0))
  7.  
  8. print(passGen(15))
  9. print(passGen(15, 0))
  10.  
  11. print(passGen(25))
  12. print(passGen(25, 0))
  13.  

Code - Python: [Select]
  1. Y?XeE,tG
  2. q%\3
  3. (v?KE5$:Xq
  4. kWPo6dIFR9
  5. 7O[ap35]2'T,i28
  6. Y4T1coxasagEqh5
  7. _fu~bJ^tGFgS}U,M+n=5<I]<N
  8. II9DxIZpQ3qw0UpBDQojTWNP4
  9.  
Title: Re: (Challenge) Password Generator
Post by: Lee Mac on August 29, 2013, 07:58:33 PM
Attached is my take on the challenge.  :-)

Great idea Mark  :-)
Title: Re: (Challenge) Password Generator
Post by: Kerry on August 29, 2013, 08:14:19 PM
Code - C#: [Select]
  1.   // Generate a new 12-character password with 1 non-alphanumeric character.
  2.   string password = Membership.GeneratePassword(12, 1)
  3.  
Namespace:  System.Web.Security
Assembly:     System.Web (in System.Web.dll)

http://msdn.microsoft.com/en-us/library/system.web.security.membership.generatepassword.aspx
Title: Re: (Challenge) Password Generator
Post by: Kerry on August 29, 2013, 08:26:39 PM

More hack ..

Code - Javascript: [Select]
  1. function passGen(code_len)
  2. {
  3.   seed= "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  4.   result = "";
  5.   for(x=0;x<code_len;x++)
  6.   {
  7.     result += seed.charAt(Math.floor(Math.random() * 62));
  8.   }
  9.   return result;
  10. }
  11.  
  12.  
  13. passGen(25); // :->  'Kjqwcxzb2YQMrWoTVBJVk6zcw'
  14.  
  15.  

That's it .. I have work to do :)
Title: Re: (Challenge) Password Generator
Post by: LE3 on August 29, 2013, 09:41:03 PM
Code - C#: [Select]
  1. [CommandMethod("PASS")]
  2. public static void PasswordMaker()
  3. {
  4.     var doc = AcadApp.DocumentManager.MdiActiveDocument;
  5.     var editor = doc.Editor;
  6.     var passwordBase = Guid.NewGuid().ToString().Replace("-", "");
  7.     var password = new StringBuilder();
  8.     var random = new Random();
  9.     const int size = 12;
  10.     for (var i = 0; i < size; i++)
  11.     {
  12.         var ch = passwordBase[random.Next(0, passwordBase.Length)];
  13.         password.Append(ch);
  14.     }
  15.     for (var i = 0; i < password.Length; i++)
  16.     {
  17.         var next = random.Next(i, password.Length);
  18.         var s = password[next].ToString(CultureInfo.InvariantCulture);
  19.         password = password.Replace(s, s.ToUpper());
  20.     }
  21.     editor.WriteMessage("\nPassword: {0} \n", password.ToString());
  22. }

Quote
Command: pass
Password: 5b559DDbACCC
Password: 64E190E26FAF
Password: 4b88C7890744
Password: 2b1051CfD410
Password: 4D80De0914F3
Password: f75fD4348234
Password: D8D4849cD0F9
Password: 8d0d98424184
Password: 0B70B9705B30
Password: 8609f604a64B
Password: B6BF7377A70A
Title: Re: (Challenge) Password Generator
Post by: JohnK on August 29, 2013, 10:43:57 PM
After some more tinkering (fixed some issues) I want to move on to creating "pronounceable" passwords and using SHA1 like PWGEN (the tool mentioned in the OP). This is fun! :D

Code: [Select]
3Afdfdb2
GhGP2A4e
d7jXm3Df
kjsicalG
dmd4XEew
7kWAZ432
ADj7ledf
4injDnks
ajBjel5d
3XLnq7IW
Title: Re: (Challenge) Password Generator
Post by: irneb on August 30, 2013, 06:34:56 AM
After some more tinkering (fixed some issues) I want to move on to creating "pronounceable" passwords and using SHA1 like PWGEN (the tool mentioned in the OP). This is fun! :D
What about one which generates a pass phrase for you like the the xkcd comic: http://xkcd.com/936/

That would probably necessitate a dictionary of words to select from. Perhaps splitting them into nouns, verbs, etc. Then generating some random sentences  :laugh: Might come up with really "strange" stuff.

Thereafter you might then use some form of mutation on those words. E.g. extract random letters from them, substituting some letters using numbers or punctuation.
Title: Re: (Challenge) Password Generator
Post by: Lee Mac on August 30, 2013, 08:19:08 AM
Letting someone else do the work...

Code - Auto/Visual Lisp: [Select]
  1. ;; Password Generator  -  Lee Mac
  2. ;; Retrieves a set of random strings from http://www.random.org
  3. ;; num - [int] Number of passwords to generate (1 - 10000)
  4. ;; len - [int] Length of each password (1 - 20)
  5. ;; bit - [int] 1=0-9, 2=A-Z, 4=a-z
  6.  
  7. (defun password ( num len bit / obj rtn )
  8.     (if (and (< 0 num 1e4) (< 0 len 21) (< 0 bit))
  9.         (if (setq obj (vlax-get-or-create-object "winhttp.winhttprequest.5.1"))
  10.             (progn
  11.                 (setq rtn
  12.                     (vl-catch-all-apply
  13.                         (function
  14.                             (lambda ( )
  15.                                 (vlax-invoke-method obj 'open "GET"
  16.                                     (strcat
  17.                                         "http://www.random.org/strings/?num="
  18.                                         (itoa num)
  19.                                         "&len="
  20.                                         (itoa len)
  21.                                         "&digits="
  22.                                         (if (= 1 (logand 1 bit)) "on" "off")
  23.                                         "&upperalpha="
  24.                                         (if (= 2 (logand 2 bit)) "on" "off")
  25.                                         "&loweralpha="
  26.                                         (if (= 4 (logand 4 bit)) "on" "off")
  27.                                         "&unique=on&format=plain&rnd=new"
  28.                                     )
  29.                                     :vlax-false
  30.                                 )
  31.                                 (vlax-invoke-method obj 'send)
  32.                                 (vlax-get-property  obj 'responsebody)
  33.                             )
  34.                         )
  35.                     )
  36.                 )
  37.                 (vlax-release-object obj)
  38.                 (if (vl-catch-all-error-p rtn)
  39.                     (princ (vl-catch-all-error-message rtn))
  40.                     (princ
  41.                         (vl-list->string
  42.                             (mapcar '(lambda ( x ) (lsh (lsh x 24) -24))
  43.                                 (vlax-safearray->list (vlax-variant-value rtn))
  44.                             )
  45.                         )
  46.                     )
  47.                 )
  48.             )
  49.         )
  50.         (princ "\nInvalid arguments.\nnum: integer 1-10,000\nlen: integer 1-20\nbit: 1=0-9, 2=A-Z, 4=a-z")
  51.     )
  52.     (princ)
  53. )

Code - Auto/Visual Lisp: [Select]
  1. _$ (password 5 10 (+ 2 4))
  2. zqldmMHEdy
  3. ktoKijAdNf
  4. YwucronUgI
  5. hsFwudZlns
  6. wAcwxhkHkL
Title: Re: (Challenge) Password Generator
Post by: JohnK on August 30, 2013, 08:57:37 AM
After some more tinkering (fixed some issues) I want to move on to creating "pronounceable" passwords and using SHA1 like PWGEN (the tool mentioned in the OP). This is fun! :D
What about one which generates a pass phrase for you like the the xkcd comic: http://xkcd.com/936/

That would probably necessitate a dictionary of words to select from. Perhaps splitting them into nouns, verbs, etc. Then generating some random sentences  :laugh: Might come up with really "strange" stuff.

Thereafter you might then use some form of mutation on those words. E.g. extract random letters from them, substituting some letters using numbers or punctuation.

lol Must have the pwgen source code.
Code - C++: [Select]
  1. /*
  2.  * pw_phonemes.c --- generate secure passwords using phoneme rules
  3.  *
  4.  * Copyright (C) 2001,2002 by Theodore Ts'o
  5.  *
  6.  * This file may be distributed under the terms of the GNU Public
  7.  * License.
  8.  */
  9. ...

But that's a good idea and sounds like fun to me! :D Damnit, now I need to see if I can scratch up some time but today looks crappy already.
Title: Re: (Challenge) Password Generator
Post by: ElpanovEvgeniy on September 05, 2013, 12:43:26 PM
my variant for autocad:

Code - Auto/Visual Lisp: [Select]
  1. (defun eea-pass (c n / f f1 G S)
  2.   ;;(eea-pass 8 5)
  3.   (defun f (s st c b i)
  4.     (if (and s (nth c s))
  5.       (cons (strcat "\n"
  6.                     (repeat c
  7.                       (setq s (cdr s)
  8.                             b (strcat b (chr (nth (rem (car s) i) st)))
  9.                       )
  10.                     )
  11.             )
  12.             (f s st c "" i)
  13.       )
  14.     )
  15.   )
  16.   (defun f1 (st)
  17.     (princ "\n\nThese are the very easy!")
  18.     (princ (apply (function strcat) (f s (vl-string->list (substr st 85)) c "" 10)))
  19.     (princ "\n\nThese are the easy ones!")
  20.     (princ (apply (function strcat) (f s (vl-string->list (substr st 59)) c "" 36)))
  21.     (princ "\n\nThese are the hard ones!")
  22.     (princ (apply (function strcat) (f s (vl-string->list (substr st 33)) c "" 62)))
  23.     (princ "\n\nThese are the harder ones!")
  24.     (princ (apply (function strcat) (f s (vl-string->list st) c "" 94)))
  25.   )
  26.   (princ "\nMove the cursor on the screen: \n")
  27.   (repeat (1+ (/ (* c n)3))
  28.     (while (equal (cadr (grread nil 5 1)) g))
  29.     (setq s (append s
  30.                     (mapcar (function (lambda (a) (apply (function +) (vl-string->list (rtos a 2 16)))))
  31.                             (trans (setq g (cadr (grread nil 5 1))) 0 '(-95.6564 -160.159 2327.53))
  32.                     )
  33.             )
  34.     )
  35.   )
  36.   (f1
  37.     "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
  38.   )
  39.   (princ)
  40. )

test:
Code: [Select]
Command: (eea-pass 8 5)

Move the cursor on the screen:


These are the very easy!
10639290
14518197
25729955
07319832
70999601

These are the easy ones!
f00r9wt0
5uvf2rj7
2912f3lz
onx5li7i
bezj36o5

These are the hard ones!
LW6Xf2zW
BQRL8Npd
YF7YB9H5
UJ3BhoDE
HKVp9cUB

These are the harder ones!
"Mw.VspM
1GH"yDfT
O5xO\z|v
+~t13e3_
7!LfzS+1

Command:

Title: Re: (Challenge) Password Generator
Post by: ElpanovEvgeniy on September 05, 2013, 12:49:37 PM
Code - Auto/Visual Lisp: [Select]
  1. (defun eea-pass (c n / f G S ST)
  2.   ;;(eea-pass 16 5)
  3.   (defun f (s st c b i)
  4.     (if (and s (nth c s))
  5.       (cons (strcat "\n"
  6.                     (repeat c
  7.                       (setq s (cdr s)
  8.                             b (strcat b (chr (nth (rem (car s) i) st)))
  9.                       )
  10.                     )
  11.             )
  12.             (f s st c "" i)
  13.       )
  14.     )
  15.   )
  16.   (princ "\nMove the cursor on the screen: \n")
  17.   (repeat (1+ (/ (* c n) 3))
  18.     (while (equal (cadr (grread nil 5 1)) g))
  19.     (setq s (append s
  20.                     (mapcar (function (lambda (a) (apply (function +) (vl-string->list (rtos a 2 16)))))
  21.                             (trans (setq g (cadr (grread nil 5 1))) 0 '(-95.6564 -160.159 2327.53))
  22.                     )
  23.             )
  24.     )
  25.   )
  26.   (setq st "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
  27.   (foreach a '(("\n\nThese are the very easy!" 85 10)
  28.                ("\n\nThese are the easy ones!" 59 36)
  29.                ("\n\nThese are the hard ones!" 33 62)
  30.                ("\n\nThese are the harder ones!" 1 94)
  31.               )
  32.     (princ (car a))
  33.     (princ (apply (function strcat) (f s (vl-string->list (substr st (cadr a))) c "" (caddr a))))
  34.   )
  35.   (princ)
  36. )
Title: Re: (Challenge) Password Generator
Post by: cadplayer on September 06, 2013, 01:49:36 PM
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.

Code: [Select]
(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 ?