(04-06-2013, 02:57 PM)Deque Wrote: (04-06-2013, 02:17 PM)Psycho_Coder Wrote: well this method would work only if the word has a length of 8, and that too all in lowercase.I think it would be wise to use a ArrayList of the characters with which we need to bruteforce the password, instead of using so many loops.
I think this is what that makes the program slow, since you have used 8 loops so it has a complexity of Big-O of 8 i.e. O(n^8) which is very inefficient. The method that I am telling that is using ArrayList of characters and then a loop to iterate the ArrayList and print the values, It will have a complexity of O(n^2), which is better.
well I maybe wrong, but this is my idea. I am sorry, if is said something wrong.
Please note that this thread is very old.
I don't think you can have a better time complexity. You can of course do it in more flexible manner. The missing flexibility is actually the big disadvantage of the code shown here.
But it is not slow in terms of time complexity. To talk about that in detail you need to clear a few things up: What is n for you? In this case it could be the length of the password, but since this algorithm shown above can only be used for one password length it is not possible to make an estimation about the time complexity for other inputs than n = 8.
Do you have pseudocode or real code for your algorithm?
The only possibilities I see in making this fast is by the usage of parallelism. This can be accomplished either with threads or the use of the GPU.
But it doesn't make sense to do this without the applying the concrete password cracking tasks to the parallel computation too.
Flexibility can be accomplished like I explained here:
http://www.hackcommunity.com/Thread-Tut-...uteforcing
This is an alternative code I made after the same principle, because it is a bit better to handle (Java):
Code:
public class WordlistGen {
private int wordNumber;
private final int wordlength;
private final char[] alphabet;
private final long maxWords;
private final int radix;
/**
* Inits a wordlist generator with given alphabet and wordlength
* @param alphabet
* @param wordlength
*/
public WordlistGen(char[] alphabet, int wordlength) {
this.wordlength = wordlength;
this.alphabet = alphabet;
this.maxWords = (long) Math.pow(alphabet.length, wordlength);
this.radix = alphabet.length;
}
/**
*
* @return next generated word, null if no word is left
*/
public String generateNext() {
if (hasNext()) {
int[] indices = convertToRadix(wordNumber);
char[] word = new char[wordlength];
for (int k = 0; k < wordlength; k++) {
word[k] = alphabet[indices[k]];
}
wordNumber++;
return new String(word);
}
return null;
}
/**
*
* @return true if there are more words to generate, false otherwise
*/
public boolean hasNext() {
return (wordNumber < maxWords);
}
private int[] convertToRadix(long number) {
int[] indices = new int[wordlength];
for (int i = wordlength - 1; i >= 0; i--) {
if (number > 0) {
int rest = (int) (number % radix);
number /= radix;
indices[i] = rest;
} else {
indices[i] = 0;
}
}
return indices;
}
}
Well co-incidentally but your post is my actual algorithm that I wanted for a bruteforcer.
Suppose three checkboxes text - [0-9], [a-z], and [A-Z]. Now if we make a bruteforcer then we will give the user the options to choose the charecters he wants for bruteforcing a pass.
we declare the max and min length of the pass.
Code:
Private minlen As Integer = 1
Private maxlen As Integer = 14
this will hold the characters
Code:
Private charset As New ArrayList()
All the characters for bruteforcing
Code:
Private lcase As String() = {"a", "b", "c", "d", "e", "f", _
"g", "h", "i", "j", "k", "l", _
"m", "n", "o", "p", "q", "r", _
"s", "t", "u", "v", "w", "x", _
"y", "z"}
Private ucase As String() = {"A", "B", "C", "D", "E", "F", _
"G", "H", "I", "J", "K", "L", _
"M", "N", "O", "P", "Q", "R", _
"S", "T", "U", "V", "W", "X", _
"Y", "Z"}
Private numbers As String() = {"0", "1", "2", "3", "4", "5", _
"6", "7", "8", "9"}
Now we create a Subroutine named createCharset()
Code:
Private Sub createCharset()
If ckhlcase.Checked Then
charset.AddRange(lower)
End If
If chkucase.Checked Then
charset.AddRange(upper)
End If
If chknumbers.Checked Then
charset.AddRange(digits)
End If
End Sub
Now the code that does the real job.
Code:
Private pwdarr As String()
Private maxr As String
Private stopbgwork As Boolean
Private Sub brute()
'Setting up the password array
pwdarr = New String(maxlen - 1) {}
For i = 0 To maxlen - 1
pwdarr(i) = "-999"
Next
num = charset.Count
'We Calculate here the total no of possible characters
total = Math.Pow(num, maxlen)
For i = 0 To maxlen
maxr = maxr & Convert.ToString(charset(Convert.ToInt32(num- 1)))
Next
'We setup the password string here
For i = 0 To min - 1
pwdarr(i) = charset(0).ToString()
Next
i = 0
'Set the First Value
While pwdarr(i) <> "-999" AndAlso stopbgwork = False
firstval += pwdarr(i)
i += 1
current += 1
End While
testpwd = firstval
updatePassword() 'A function call to check the generated pass with the encrypted pass(if any, this is an optional step, I created this just to cover all the possibilities of Bruteforcing)
While True AndAlso stopbgwork = False
For i = 0 To (maxlen + 1) - 1
If pwdarr(i) = "-999" Then
Exit For
End If
Next
i -= 1
inc_comp = False
While Not inc_comp
For j = 0 To num - 1
If pwdarr(i) = charset(j).ToString() Then
Exit For
End If
Next
If j = (numVals - 1) Then
pwdarr(i) = charset(0).ToString()
updatePassword()
current += 1
i -= 1
If i < 0 Then
For i = 0 To (max + 1) - 1
If pwdarr(i) = "-999" Then
Exit For
End If
Next
pwdarr(i) = charset(0).ToString()
pwdarr(i + 1) = "-999"
updatePassword()
current += 1
inc_comp = True
End If
Else
pwdarr(i) = charset(j + 1).ToString()
updatePassword()
current += 1
inc_comp = True
End If
End While
End While
i = 0
currentval = ""
While pwdarr(i) <> "-999"
currentval = currentval & pwdarr(i)
i += 1
testpwd = currentval
updatelabel(label1, passString()) 'A label in the GUI where the randomly generated passwords are displayed.
If currentval = maxr Then
Exit While
End If
End While
End Sub
Private Function passString() As String
Dim tmp As String = ""
For x As Integer = 0 To maxlen - 1
tmp += pwdarr(x)
Next
Return tmp.Replace("-999", "")
End Function
This is a rough code and might contains error, but I think I made my point clear. However , your paper on bruteforcing is best. I have tried to do like it.