Jump to content
Sign in to follow this  
Drifter

Issue with arrays

Recommended Posts

Drifter

I have included comments in my programming to try to make my intent clear, i hope it is adequate.

#cs

DISCLAIMER: I do not intend this script to be used for malicious purposes! It is intended solely for exploration
into computer security issues.

    The purpose of this program will be to generate a random "password" and set it to a variable. The
program will then run through all possible combinations of lower case letters in order to "force crack" the
password. This is done in the interest of seeing how long it would take to crack various passwords using only
the brute force method.

#ce

$password = "text here"

;crack a password up to 1 characters long
forceCrack(1)

Func forceCrack($n)
    ;$array is the guessed password
    ;the array contains n elements, and in the second dimension, 0 refers to the number value and 1 is the char.
    
    ;NOTE: The programming of this Func is not yet complete
    Global $array[$n][2]
    
    ;-1 is a default value telling the program the string is empty, 0-25 = a-z.
    For $i = 0 To $n-1
        $array[$i][0] = -1
    Next
    
    ;change the guessed pass to the first possibility. change should go from "" to "a".
    increment($n)
    
    ;set the chars based on the numbers representing them
    setLetters($n)
    $str = getStr($n)
    
    ;display password guess, should be "a".
    ToolTip($str)
    
EndFunc

Func increment($n)
    
    $idx = $n-1
    
    ;find place to increment
    While 1
        If $array[$idx][0] < 0 Then
            $idx -= 1
        Else
            ExitLoop(1)
        EndIf
    WEnd
    
    ;hold its place in temp
    $temp = $idx
    
    ;now increment
    $array[$idx][0] += 1
    
    ;check to see if value is valid and increment others if value is beyond "z".
    While $array[$idx][0] > 25
        $array[$idx][0] = 0
        $idx -= 1
        
        If $idx >= 0 Then
            $array[$idx][0] += 1
        ElseIf ($idx = -1) And ($temp + 1 < $n) Then
            $array[$temp + 1][0] += 1
            ExitLoop(1)
        ElseIf $idx = -1 Then
            ;end program, all possible values done. At this point the guessed pass is something like "zzzz".
            Exit
        EndIf
    WEnd
    
EndFunc

Func setLetters($n)
    
    For $i = 0 To $n-1
        $temp = $array[$i][0]
        
        If $temp = -1 Then
            ;char does not exist
            $array[$i][1] = ""
        ElseIf $temp >= 0 Then
            $array[$i][1] = Chr(Asc("a") + $temp)
        EndIf
    Next
    
EndFunc

Func getStr($n)
    $string = ""
    
    For $i = 0 To $n-1
        $string &= $array[$i][1]
    Next
    
    Return $string
    
EndFunc

The error i get is as follows:

C:\[+]Macro Scripts\Game Loader\test.au3 (48) : ==> Array variable subscript badly formatted.:

If $array[$idx][0] < 0 Then

If $array[^ ERROR

>Exit code: 1 Time: 0.214

(If it is not clear, the error is thrown in Func "increment")

Why does this happen? I wondered at first if it was because i used "Global" inside a function, but this shouldnt be it as it would say the variable wasnt declared. Advice please? :blink:

Share this post


Link to post
Share on other sites
Drifter

My apologies. I figured out what was wrong. It seems posting it made me take a better look. I really need to work on my debugging skills? :blink:

The error is that if you start with $n = 1, the program decreases the array index to something that makes no sense (like -1).... ive fixed it and it works now, thanks anyway!

Share this post


Link to post
Share on other sites
goldenix

thats because you cant read something from array Row 0 ->$array[$idx][0] = $array[0][0]

Rows start from Row 1, row 2, etc.

now if you will try this $array[1][0] you will get array subscripts range exeeded error because you did not re declare the array, means you did not add new rows into the array:

Global $array[1][2]; 1 row 2 columns in the beginning

And lather you add new rows. see sample:

#include <Array.au3>
Dim $avArray[1][2] ;1 Row & 2 columns at the beginning 

For $x = 1 To 10
    $iRow = UBound($avArray)    ;add Rows
    $iCol = UBound($avArray, 2) ;Add Columns

    ReDim $avArray[$iRow + 1][$iCol]    ; add more rows +1 ; ReDim $avArray[$iRow + 1][$iCol + 1] - Adds both

    $avArray[$x][0] = $x
    $avArray[$x][1] = $x
Next
 _ArrayDisplay($avArray, "$avArray")

edit: hehh, u already fixed it

edit 2 note that re dim = add more rows or columns is slow so if u plan adding 1 row at the time ur script will be slow, I suggest you know beforehand how many rows you need. or add more rows at the same time each time u need to add some to make ur script faster

Edited by goldenix

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites
seandisanti

thats because you cant read something from array Row 0 ->$array[$idx][0] = $array[0][0]

Rows start from Row 1, row 2, etc.

now if you will try this $array[1][0] you will get array subscripts range exeeded error because you did not re declare the array, means you did not add new rows into the array:

Global $array[1][2]; 1 row 2 columns in the beginning

And lather you add new rows. see sample:

#include <Array.au3>
Dim $avArray[1][2] ;1 Row & 2 columns at the beginning 

For $x = 1 To 10
    $iRow = UBound($avArray)    ;add Rows
    $iCol = UBound($avArray, 2) ;Add Columns

    ReDim $avArray[$iRow + 1][$iCol]    ; add more rows +1 ; ReDim $avArray[$iRow + 1][$iCol + 1] - Adds both

    $avArray[$x][0] = $x
    $avArray[$x][1] = $x
Next
 _ArrayDisplay($avArray, "$avArray")

edit: hehh, u already fixed it

edit 2 note that re dim = add more rows or columns is slow so if u plan adding 1 row at the time ur script will be slow, I suggest you know beforehand how many rows you need. or add more rows at the same time each time u need to add some to make ur script faster

and rather than generating and testing each possible permutation, you can just download a rainbow file, read it into an array, and then test each element for a way quicker force

Share this post


Link to post
Share on other sites
Drifter

actually there is nothing wrong with the global declaration. I simply forgot to tell the program to stop looking for where the letters need changed when the index is -1.

Edit: What exactly is a rainbow file? im just starting to explore computer security issues and im trying to look now at better methods of cracking like dictionary hacking or etc, since this method ive completed.

Edited by Drifter

Share this post


Link to post
Share on other sites
seandisanti

yeah. but basically it's just a pre-made list of permutations, so that instead of having your computer generate them one at a time, you can download one of those and load it into memory, then your biggest time sink is any imposed delay on attempts

Share this post


Link to post
Share on other sites
Drifter

actually it "generates" the permutations very quickly. For lower case letters and 2 max letters pass its basically instant to go from "a" to "zz". Im still working on implimenting a GUI and a timer system for it though but i think even if i go to 8 letters it could do all of them internally checking VERY fast. I think the most time taken is using "Send(pass)" and waiting for whatever interface to respond, not that i intend to set it up to an interface as i am NOT trying to actually force crack, only demonstrate how its done :blink:

Share this post


Link to post
Share on other sites
seandisanti

actually it "generates" the permutations very quickly. For lower case letters and 2 max letters pass its basically instant to go from "a" to "zz". Im still working on implimenting a GUI and a timer system for it though but i think even if i go to 8 letters it could do all of them internally checking VERY fast. I think the most time taken is using "Send(pass)" and waiting for whatever interface to respond, not that i intend to set it up to an interface as i am NOT trying to actually force crack, only demonstrate how its done :blink:

it will not ever generate a permutation as quickly as it can pull one from memory, that is not up for debate

Share this post


Link to post
Share on other sites
Drifter

i suppose i am not debating that. however, since the time to generate each pass is far far under a milisecond, why should i be concerned? Again all the time would really be taken up by entering a pass and seeing if it is correct. It is not that i don't welcome suggestions, im just not seeing why which approach one takes would matter here.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×