Sign in to follow this  
Followers 0
blademonkey

Random Password Generator Ver2

16 posts in this topic

#1 ·  Posted (edited)

Hey Guys,

This is a two part post. The first part being that I am attempting (emphasis on attempt) to give back to this amazing community who has been more than helpful to me.

The second part being my coming of age in this autoit/pseudo-programming environment, and how I would like to evolve my code into a more modular fashion.

The code I will post was the product of my hard work today. As I am a noob, it took me almost all day at work (while ignoring most of my other tasks) to get the code to work.

here is a little background. The code is a Random (primitive) Password Generator that meets the following five requirements (as required by my workplace):

- must have at least one lowercase

- must have at least one uppercase

- must have at least one number

- must have at least one special character

- must be at least 8 characters long.

That being said, I open my code up for your worldly critique (if anyone even cares). My request to you is that you suggest a better way for me to code, so that I am call this specific function from another AU3 script that will be a GUI.

The master plan is to convert all my former (and hopefully future) scripts in a way that I can call most (not all) of them through a GUI.

Ok here it is.

#include <Array.au3>
opt("trayicondebug", 1)
; Script Start - Add your code below here
;~ *******************************************
;~ Variables
;~ *******************************************

$x = 26
$pwdlength = InputBox("Password Length","How long do you want your password to be?"&@lf&"Default is 8 max is 32",8)
$z = 11
dim $Lowercase[$x]
dim $Uppercase[$x]
Dim $Password[$pwdlength]
Dim $Numeric[10]
Dim $Special[$z]
DIm $pos[$pwdlength]
Dim $req[4]
$req[0] = "Lowercase"
$req[1] = "Uppercase"
$req[2] = "Numeric"
$req[3] = "Special"


;~ *******************************************
;~ Main Process
;~ *******************************************
for $j = 0 to ($x-1) ;      Set Arrayitem = ASCII Char + Array position;;   
    $Lowercase[$j] = chr(97 + $j)
    $uppercase[$j] = chr(65 +$j)
Next

For $j = 0 to 9     ;       Set Arrayitem = ASCII Char + Array position;; 
    $Numeric[$j] = chr(48 + $j)
Next    

For $j = 0 to 10    ;       Set Arrayitem = ASCII Char + Array position;; 
    $special[$j] = chr(33 +$j)
Next

$Uppercase_size = Ubound($uppercase) 
$Lowercase_size = Ubound($Lowercase)
$numeric_size = Ubound($numeric)
$Special_Size = UBound($Special)

_randompassword()


$rndm_pass =_ArrayToString($Password," ");      convert all elements of the $password Array into a String called $RNDPASS
$rndm_pass = StringReplace($rndm_pass," ","");      Eleminate the spaces from the $rndmpass String

MsgBox(0,"password",$rndm_pass)

exit 
;~ *******************************************
;~ FUNCTIONS
;~ *************************** ****************
Func _randompassword()
For $j = 0 to 3
    $pos[$j] = random(0, $pwdlength -1,1)
    if  isstring($Password[$pos[$j]])= 1 Then
        do
        $pos[$j] = random(0, $pwdlength -1,1)
        until isstring($Password[$pos[$j]])= 0 
    endif
        $req_crit=$req[$j]; ex: $reg[$j] = lowercase
        $req_crit_array = eval($req_crit);ex; $test = $lowercase
        $password[$pos[$j]] = $req_crit_array[random(0,eval($req_crit&"_Size")-1,1)]
next 

For $j = 4 to $pwdlength-1
    $pos[$j] = random(0, $pwdlength -1,1)
    if  isstring($Password[$pos[$j]])= 1 Then
        do
        $pos[$j] = random(0, $pwdlength -1,1)
        until isstring($Password[$pos[$j]])= 0 
    endif
    $random_crit = $req[random(0,3,1)]
    $random_crit_array = eval($random_crit) 
    $password[$pos[$j]] = $random_crit_array[random(0,eval($random_crit&"_Size")-1,1)]
next 

EndFunc

PS: please be gentle, im not very good with arrays.

Edit: typo.

Random_Password_Generator_1.0.au3

Edited by blademonkey

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hey All,

Does anyone know of a way to dim a EVALed result as the variable array?

For Instance

$x= 4
$variable = "first"
DIM EVAL($variable &  "sometext")[$x]

would be the same than

DIM $first_sometext[4]
[code=auto:0]

Any advise would be appreciated.

-Monkey

Edit: fixed Typos.


            
                


    Edited  by blademonkey
    
    

            
        

        
            
                

    
        
            
        
    


            
        

        
            
                
                
                
            
            
                
            
        
        
            




  
  
    ---"Educate the Mind, Make Savage the Body" -Mao Tse Tung
  


        
    

    
        
            Share this post
            
Link to post
            
            
            

            
                Share on other sites
                

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    

            
        
    


    

                    
                
                    
                    
                    






    
    
        
blademonkey   

    
        
    
             4
    
        
    

        
            
                Universalist
            
            

            
                

    
        
    

            
            Active Members
            
            
                

    
        
    
             4
    
        
    

                416 posts
                
                

            
        
    
    
        


    

    
        
            
            
                
            
            
        

        
    #3 · 
            Posted 
            
            
            
        
    

    


            
        
            Ok either my code sucks or it's not worth anyone's time. {= (.

I'll recode it or something....


            
        

        
            
                

    
        
            
        
    


            
        

        
            
                
                
                
            
            
                
            
        
        
            




  
  
    ---"Educate the Mind, Make Savage the Body" -Mao Tse Tung
  


        
    

    
        
            Share this post
            
Link to post
            
            
            

            
                Share on other sites
                

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    

            
        
    


    

                    
                
                    
                    
                    






    
    
        
SmOke_N   

    
        
    
             178
    
        
    

        
            
                It's not what you know ... It's what you can prove!
            
            

            
                

    
        
    

            
            Moderators
            
                
            
            
                

    
        
    
             178
    
        
    

                16,119 posts
                
                

            
        
    
    
        


    

    
        
            
            
                
            
            
        

        
    #4 · 
            Posted 
            
            
            
        
    

    


            
        
            Could you give an actual example of what the array would consist of?

ie... Initial values / desired return values / how you were planning on creating the array to begin with...


            
        

        
            
                

    
        
            
        
    


            
        

        
            
                
                
                
            
            
                
            
        
        
            




  
  
    [center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]
  


        
    

    
        
            Share this post
            
Link to post
            
            
            

            
                Share on other sites
                

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    

            
        
    


    

                    
                
                    
                    
                    






    
    
        
blademonkey   

    
        
    
             4
    
        
    

        
            
                Universalist
            
            

            
                

    
        
    

            
            Active Members
            
            
                

    
        
    
             4
    
        
    

                416 posts
                
                

            
        
    
    
        


    

    
        
            
            
                
            
            
        

        
    #5 · 
            Posted 
            
                (edited)
            
            
            
        
    

    


            
        
            Could you give an actual example of what the array would consist of?

ie... Initial values / desired return values / how you were planning on creating the array to begin with...oh wow a bite! {= D

Sure, I'll try to explain my insanity.

After having posted my code, and sent a working copy to my security team, to which they asked me to add a feature that would correlate each character (be it Alpha upper,lower, numeric or special) to words and make a passphrase out of it.  So a password of MhalL would have a passphrase of MaryhadalittleLamb.

working with my current RPGenerator, I created four files: Lowercase.txt, Uppercase.txt, Numeric.txt, and Special.txt.  All name in accordance to their correlating Arrays.

Since I have the following for loop in my previous code.

For $j = 0 to 3
    $pos[$j] = random(0, $pwdlength -1,1)
    if   isstring($Password[$pos[$j]])= 1 Then
        do
        $pos[$j] = random(0, $pwdlength -1,1)
        until isstring($Password[$pos[$j]])= 0
    endif
        $req_crit=$req[$j]; ex: $reg[$j] = lowercase
        $req_crit_array = eval($req_crit);ex; $test = $lowercase
        $password[$pos[$j]] = $req_crit_array[random(0,eval($req_crit&"_Size")-1,1)]
next

I want to be able to create a Variable Array whose name is dependent on the Array Position of $req[] that the count of the for loop designates.

As opposed to doing a manual array declarate for each , I want the code to do it.

For example,

if $j = 0 then $req[$j] = lowercase

so then I want to declare an array where the name is equal to the result of $req[$j] + some random text.

they only way I know how to illustrate this was to do a

DIM (eval($req[$j] & "_text") )[$x]

I want to be able to add this line in the code

$file[$j] = $Req[$j] & ".txt"
Fileopen($file[$j] )
$arraysize = _FileCountLines($file[$j])
DIM eval($req[j$] & "_file" )[$arraysize]

if you assume that $j=0 then the code would be like this:

$req[$j] = "Lowercase"
$File[$j] = "Lowercase"&".txt"
Fileopen("Lowercase.txt")
$arraysize = _FileCountLines("Lowercase.txt"); lowercase has 26 entries so $arraysize = 26
DIM  eval(Lowercase & _file)[26]

I hope that clears things up.

That last line is what i need to have done. I want it to say :

DIM $lowercase_file[26]

I have a working stand alone version of the passphrase but it's not pretty and it only works with lowercase characters. all other characters are treated as 0 or "a'.

I'll post it to show you what I mean.

Thanks for the effort

-Blademonkey

Edit:typo.

Random_Passphrase_Generator.au3

Lowercase.txt

UpperCase.txt

numeric.txt

special.txt

Edited by blademonkey

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Share this post


Link to post
Share on other sites

Ugh!!... This right up Seans (camernsdad) alley!!... He lives for this stuff!

One thing before I go blow my brains out after reading that... Have you told your peers/bosses to kiss your *ss?

Ok... Time to ;) + :lmao: = o:)


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Ugh!!... This right up Seans (camernsdad) alley!!... He lives for this stuff!

One thing before I go blow my brains out after reading that... Have you told your peers/bosses to kiss your *ss?

Ok... Time to ;) + :lmao: = o:)

Yea, I know the code is sloppy. That's mainly due to the fact that my grasp of Autoit is still in its infancy(obviously).

I think the comment about my peers/bosses was a compliment. Thanks.

I rather earn the respect of the community by improving my code than getting my peers or my bosses to kiss my "adoresellsell" {= ).


---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Share this post


Link to post
Share on other sites

I'm bumping this to see if Cameronsdad will bite, since smoke siad it was right up his alley (not blowing smoke up anyone's alley though!).

{=D

$Location = traceroute(Cameronsdad)

Ping $location

if @error = 0 then

praise the lord

else

keep on keeping on

endif


---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Share this post


Link to post
Share on other sites

bump


---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

You won't see Sean till Monday Monkey...

Edit:

Since you've released it here... why not try posting in the support forum (couldn't hurt).

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

You won't see Sean till Monday Monkey...

Edit:

Since you've released it here... why not try posting in the support forum (couldn't hurt).

I have already. This was posted in there and moved here... I'm all confused now...

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Share this post


Link to post
Share on other sites

Alrighty!

I've figured out how to make a passphrase out of the random password that will help people remember it.

if anyone cares just throw the code and the four Text files in the same Folder and run it.

It's pretty sloppy right now, but it does what I intended it to do.

#include <Array.au3>
#include <file.au3>

$x = 26

Do 
    $pwdlength = InputBox("Password Length","How long do you want your password to be?"&@lf&"Default is 8 max is 32",8)
    If $pwdlength < 8 Then
    MsgBox(0,"Error","Password length to small")
    EndIf
Until $pwdlength >= 8

$z = 11
dim $Lowercase[$x],$Uppercase[$x],$Password[$pwdlength],$passphrase[$pwdlength],$Numeric[10],$Special[$z],$pos[$pwdlength],$req[4]
Dim $Lowercase_file[$x],$uppercase_file[$x],$numeric_file[10],$Special_file[$z]
$req[0] = "Lowercase"
$req[1] = "Uppercase"
$req[2] = "Numeric"
$req[3] = "Special"


for $j = 0 to ($x-1)                        ;       Set Arrayitem = ASCII Char + Array position;;    
    $Lowercase[$j] = chr(97 + $j)
    $uppercase[$j] = chr(65 +$j)
Next
For $j = 0 to 9                            ;        Set Arrayitem = ASCII Char + Array position;;
    $Numeric[$j] = chr(48 + $j)
Next    
For $j = 0 to 10                           ;        Set Arrayitem = ASCII Char + Array position;;
    $special[$j] = chr(33 +$j)
Next

$Uppercase_size = Ubound($uppercase)
$Lowercase_size = Ubound($Lowercase)
$numeric_size = Ubound($numeric)
$Special_Size = UBound($Special)

For $j = 0 to 3
    $current_file= $req[$j]&".txt"
    $Current_array = eval($req[$j] & "_file")
    FileOpen($current_file,0)
    _FileReadtoarray($current_file, $Current_array)
    _ArrayDelete($Current_array, 0)

    $pos[$j] = random(0, $pwdlength -1,1)
    if   isstring($Password[$pos[$j]])= 1 Then
        do
        $pos[$j] = random(0, $pwdlength -1,1)
        until isstring($Password[$pos[$j]])= 0
    endif
        $req_crit=$req[$j]; ex: $reg[$j] = lowercase
        $req_crit_array = eval($req_crit);ex; $test = $lowercase
        $password[$pos[$j]] = $req_crit_array[random(0,eval($req_crit&"_Size")-1,1)]
        $ele_key = _ArrayBinarySearch($req_crit_array,$password[$pos[$j]])
        $passphrase[$pos[$j]] = $Current_array[$ele_key]
next

For $j = 4 to $pwdlength-1
    $pos[$j] = random(0, $pwdlength -1,1)
    if   isstring($Password[$pos[$j]])= 1 Then
        do
            $pos[$j] = random(0, $pwdlength -1,1)
        until isstring($Password[$pos[$j]])= 0
    endif
    $random_crit = $req[random(0,3,1)]
    $random_crit_array = eval($random_crit)
    $password[$pos[$j]] = $random_crit_array[random(0,eval($random_crit&"_Size")-1,1)]
    $current_file= $random_crit&".txt"
    $Current_array = eval($random_crit & "_file")
    _FileReadtoarray($current_file, $Current_array)
    _ArrayDelete($Current_array, 0)
    $ele_key = _ArrayBinarySearch($random_crit_array,$password[$pos[$j]])
    $passphrase[$pos[$j]] = $Current_array[$ele_key]
next


$rndm_pass =_ArrayToString($Password," ")   ;       convert all elements of the $password Array into a String called $RNDPASS
$rndm_pass = StringReplace($rndm_pass," ","");      Eleminate the spaces from the $rndmpass String
$rndm_passphrase =_ArrayToString($passphrase,"_")   ;       convert all elements of the $password Array into a String called $RNDPASS
;~ $rndm_passphrase = StringReplace($rndm_passphrase,"_",""); Uncomment this line if you want the Passphrase to take out the delimiter '_'

MsgBox(0,"password","Your New Random Password is :" & @TAB & $rndm_pass  &@TAB & @CRLF & $rndm_passphrase)
exit

Downloading Autoit --------------------------------------- Free

Learning Autoit ------------------- ------------------------ Lots of hours

Materializing thought to functional code----------------- Priceless

Lowercase.txt

UpperCase.txt

special.txt

numeric.txt


---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Share this post


Link to post
Share on other sites

I'm bumping this to see if Cameronsdad will bite, since smoke siad it was right up his alley (not blowing smoke up anyone's alley though!).

{=D

$Location = traceroute(Cameronsdad)

Ping $location

if @error = 0 then

praise the lord

else

keep on keeping on

endif

ah, yeah, ron had told me to try to find your post that it was one for me, but didn't link me, so this is the first i'm seeing of this. i DID post to your original thread in the support forum with some alternate code, but as far as the new feature to be added, i see you have figured out a way to do what you want, i'll whip up an alternate way and append it to this post.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

ah, yeah, ron had told me to try to find your post that it was one for me, but didn't link me, so this is the first i'm seeing of this. i DID post to your original thread in the support forum with some alternate code, but as far as the new feature to be added, i see you have figured out a way to do what you want, i'll whip up an alternate way and append it to this post.

here we go... this generates a hint for them too. went with a select case because i was going to have the words, example, if the character was a "-" it would say "hyphen" but then i figured that the symbol/number is as good as the word for said number/symbol.

Func Mnemonicer($word)
    $allLetters = "abcdefghijklmnopqrstuvwxyz"
    Dim $Words[23]
    $Words[0] = 52
    $Words[1] = "apple"
    $Words[2] = "banana"
    $Words[3] = "cartel"
    $Words[4] = "demonic"
    $Words[5] = "ellipsical"
    $Words[6] = "fart"
    $Words[7] = "gargantuan"
    $Words[8] = "hospital"
    $Words[9] = "intolerable"
    $Words[10] = "jackassery"
    $Words[11] = "killer"
    $Words[12] = "loves"
    $Words[13] = "monkey"
    $Words[14] = "nostalgic"
    $Words[15] = "open"
    $Words[16] = "platinum"
    $Words[17] = "quintessential"
    $Words[18] = "retarded"
    $Words[19] = "stupid"
    $Words[20] = "terrible"
    $Words[21] = "ugly"
    $Words[22] = "voracious"
    $Words[23] = "whipped"
    $Words[24] = "xenophobic"
    $Words[25] = "youthful"
    $Words[26] = "zebras"
    $Words[27] = "Adam"
    $Words[28] = "Bernice"
    $Words[29] = "Candy"
    $Words[30] = "Denise"
    $Words[31] = "Emily"
    $Words[32] = "Fred"
    $Words[33] = "George"
    $Words[34] = "Harold"
    $Words[35] = "Ishmael"
    $Words[36] = "Jasmine"
    $Words[37] = "Kathy"
    $Words[38] = "Lucy"
    $Words[39] = "Michelle"
    $Words[40] = "Nancy"
    $Words[41] = "Olivia"
    $Words[42] = "Paul"
    $Words[43] = "Quinn"
    $Words[44] = "Rebecca"
    $Words[45] = "Sean"
    $Words[46] = "Theresa"
    $Words[47] = "Ursela"
    $Words[48] = "Veronica"
    $Words[49] = "Wilma"
    $Words[50] = "Xavier"
    $Words[51] = "Yak"
    $Words[52] = "Zanzibar"
    $temp = ""
    For $x = 1 to StringLen($word)
        Select
        Case StringInStr($allLetters,StringLower(StringMid($word,$x,1)));character being examined is a letter
            $i = 1
            While 1
                If StringLeft($Words[$i],1) = StringMid($word,$x,1) Then
                    $temp = $temp & $Words[$i]
                    ExitLoop
                Else
                    $i = $i + 1
                EndIf
            WEnd
        Case Else
            $temp = $temp & StringMid($word,$x,1)
        EndSelect
    Next
    MsgBox(0,"Remember Me",$temp)
EndFunc

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Damn, that rocks.

Uh... my code has become this sort of monster. I wrapped some nasty sloppy GUI onto it.

I thank you for posting your awesomely optimized code and I am kinda of glad I didnt see it until after I made my work. It's totally worth all the sweat (even if it's not pretty).

man, if I can just be as good of a coder as you I'd have more space on my HD {= D.

anyway here's the latest Greatest code (with GUI)

#include <Array.au3>
#include <file.au3>
#include <GuiConstants.au3>
#include <string.au3>

opt("trayicondebug", 1)
Opt("GUIOnEventMode", 1)

If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000

$RPG = GuiCreate("Random Password Generator", 350, 200,(@DesktopWidth-217)/2, (@DesktopHeight-182)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$Button_1 = GuiCtrlCreateButton("Generate", 170, 170, 50, 20)
$Edit_2 = GUICtrlCreateEdit("", 5, 5, 300, 150, $ES_MULTILINE+$ES_AUTOVSCROLL+$ES_READONLY)
$Clear_But = GuiCtrlCreateButton("Clear", 100, 170, 50, 20)
$Gui_length =GUICtrlCreateInput(8, 5, 170,20,20)
GUICtrlSetOnEvent($Button_1, "Button_1")
GUICtrlSetOnEvent($Clear_But, "Clear")
GuiSetState()
While 1
sleep(100)
WEnd
Exit
 


Func _randompassword()
Do
    $pwdlength= GUICtrlRead($Gui_length)
;~  $pwdlength = InputBox("Password Length","How long do you want your password to be?"&@lf&"Default is 8 max is 32",8)
    If $pwdlength < 8 Then
    MsgBox(0,"Error","Password length to small")
    $pwdlength = 8
    GUICtrlSetData($Gui_length,8)
    Else 
    If $pwdlength > 100 Then
    MsgBox(0,"Error", "Password length WAY TOO LONG!"&@lf&"Please Try again")
    $pwdlength = 8
    GUICtrlSetData($Gui_length,8)
;~  sleep(5000)
    EndIf
    EndIf
Until $pwdlength >= 8 and $pwdlength <= 100

$x = 26
$z = 11
dim $Lowercase[$x],$Uppercase[$x],$Password[$pwdlength],$passphrase[$pwdlength],$Numeric[10],$Special[$z],$pos[$pwdlength],$req[4]
Dim $Lowercase_file[$x],$uppercase_file[$x],$numeric_file[10],$Special_file[$z]
$req[0] = "Lowercase"
$req[1] = "Uppercase"
$req[2] = "Numeric"
$req[3] = "Special"


for $j = 0 to ($x-1)                    ;       Set Arrayitem = ASCII Char + Array position;;    
    $Lowercase[$j] = chr(97 + $j)
    $uppercase[$j] = chr(65 +$j)
Next
For $j = 0 to 9                           ;     Set Arrayitem = ASCII Char + Array position;;
    $Numeric[$j] = chr(48 + $j)
Next    
For $j = 0 to 10                          ;     Set Arrayitem = ASCII Char + Array position;;
    $special[$j] = chr(33 +$j)
Next

$Uppercase_size = Ubound($uppercase)
$Lowercase_size = Ubound($Lowercase)
$numeric_size = Ubound($numeric)
$Special_Size = UBound($Special)

For $j = 0 to 3
    $current_file= $req[$j]&".txt"
    $Current_array = eval($req[$j] & "_file")
    FileOpen($current_file,0)
    _FileReadtoarray($current_file, $Current_array)
    _ArrayDelete($Current_array, 0)

    $pos[$j] = random(0, $pwdlength -1,1)
    if   isstring($Password[$pos[$j]])= 1 Then
        do
        $pos[$j] = random(0, $pwdlength -1,1)
        until isstring($Password[$pos[$j]])= 0
    endif
        $req_crit=$req[$j]; ex: $reg[$j] = lowercase
        $req_crit_array = eval($req_crit);ex; $test = $lowercase
        $password[$pos[$j]] = $req_crit_array[random(0,eval($req_crit&"_Size")-1,1)]
        $ele_key = _ArrayBinarySearch($req_crit_array,$password[$pos[$j]])
;~      ConsoleWrite("Array: " & $req[$j] & "|"  & "Current_Key: " & $ele_key &"|"& "Loopcount" & $j & @lf)
        
        $passphrase[$pos[$j]] = $Current_array[$ele_key]
next

For $j = 4 to $pwdlength-1
    $pos[$j] = random(0, $pwdlength -1,1)
    if   isstring($Password[$pos[$j]])= 1 Then
        do
            $pos[$j] = random(0, $pwdlength -1,1)
        until isstring($Password[$pos[$j]])= 0
    endif
    $random_crit = $req[random(0,3,1)]
    $random_crit_array = eval($random_crit)
    $password[$pos[$j]] = $random_crit_array[random(0,eval($random_crit&"_Size")-1,1)]
    $current_file= $random_crit&".txt"
    $Current_array = eval($random_crit & "_file")
    _FileReadtoarray($current_file, $Current_array)
    _ArrayDelete($Current_array, 0)
    $ele_key = _ArrayBinarySearch($random_crit_array,$password[$pos[$j]])
;~  ConsoleWrite("Value: " & $random_crit_array[$ele_key] & "|"  & "Array: " & $random_crit & "|"  &"Current_Key: " & $ele_key &"|"& "Loopcount" & $j & "|"  & "Pos: " & $pos[$j]&$Current_array[$ele_key] & " " & $current_file &@lf)
    $passphrase[$pos[$j]] = $Current_array[$ele_key]
next


$rndm_pass =_ArrayToString($Password," ")  ;        convert all elements of the $password Array into a String called $RNDPASS
$rndm_pass = StringReplace($rndm_pass," ","");      Eleminate the spaces from the $rndmpass String
$rndm_passphrase =_ArrayToString($passphrase,"_")  ;        convert all elements of the $password Array into a String called $RNDPASS
;~ $rndm_passphrase = StringReplace($rndm_passphrase,";","")

$previous_pass = GUICtrlRead($Edit_2)
GUICtrlSetData( $Edit_2,$previous_pass &@crlf&"------------------------------------"&@Crlf &"Password:"&@tab &$rndm_pass& @crlf& "Passphrase:" &@tab &$rndm_passphrase)
EndFunc

Func Button_1()
_randompassword()  
EndFunc
Func Clear()
    GUICtrlSetData( $Edit_2,"")
EndFunc
Func CLOSEClicked()
    Exit
EndFunc
Func GetLength()



EndFunc

I am going to print out your code and learn from it. Geez, I feel so dumb.

Edited by blademonkey

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Share this post


Link to post
Share on other sites

Damn, that rocks.

Uh... my code has become this sort of monster. I wrapped some nasty sloppy GUI onto it.

I thank you for posting your awesomely optimized code and I am kinda of glad I didnt see it until after I made my work. It's totally worth all the sweat (even if it's not pretty).

man, if I can just be as good of a coder as you I'd have more space on my HD {= D.

anyway here's the latest Greatest code (with GUI)

I am going to print out your code and learn from it. Geez, I feel so dumb.

I'm glad you liked it. In your other post you were talking about having it in functions so you could re-use etc, that's why i did both as functions. as far as being as good as me, i have no doubt that with some practice you'll be atleast as comfortable with autoit as i am. a few things you can do to quickly boost your abilities with autoit though, are:

1) be active on the forums. and i know you are, i'm sure you've learned some stuff even while helping others. personally i think i've learned more working on other people's projects than i have getting my own to work. that's just because with my own codes, i have a desired result when i start, and as receive that result, i consider the project done (except for added features etc, which i invariably put in after the fact), but with other people's projects, i have to think more, trying to understand why they're tryign to do what they're tryign to do, how they could mis-use the code etc etc etc, and usually i'm more satisfied with the code that i write for others than stuff that i do for myself.

2) read programming books. you're not going to go to the library and find a book on autoit (and i stopped work on mine when someone else's guide hit the forum), but books on ANY language will help you. Lots of things are universal in programming, loops, conditions, variables, arrays, etc; and even though the syntax is different, you can still get some quality info from books on different languages. One of my favorite books, that's helped me optimize alot of my code is called "Data Structures and Algorithms in Java".

3) go to challenge sites. whenever i start a new language, i used to go to challenge sites like arcanum.co.nz (more on the list at hackergames.net) and do the programming challenges in the language i was trying to learn. I've just found that it's easier to learn with directed learning, so in learning how to do a specific thing that you need to do for a challenge, you end up learning more than you would have thought to look up yourself on a whim. One of the challenges on arcanum that i particularly enjoyed had a text file to be imported. it was a 3 dimensional cube of letters, just "ABCD" and other permutations of those letters over and over in 100 100x100 squares. the object of the challenge was to identify how many times the string "ABCD" occured in any direction in the cube. From any given point in the cube, there were 28 directions to check. Good stuff, and with those sites, you're guaranteed to be forced to think outside the box (no pun intended).

And dude, don't feel dumb. you came up with a working solution to your problem as was your goal. you learn as you apply your knowledge, and your code is just going to get better and better. [/rant]


1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0