generate any possible password in lowercase alpha

Pages: 12
generate any possible combination of words to find the passwords of any length in lowercase alphabits (a to z)

this piece of code prints more than 500 combinations (if there are more than 500) per second on intel core i3,i5,i7 processor family...
this code can be modified to make it more faster only you have to do is to make a file instead of printing the words on the screen about more than 50,000 combinations per second...

for more information mail me at "ubaidazad@gmail.com"


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream.h>
#include <conio.h>
#include <fstream.h>
#include <math.h>
int index_z=0,min,max;
char alpha[10],temp;
inline void intialize_values(int m) {
     for (int j=0;j<m;j++)
     { alpha[j]='a'; }
     }
inline int increament(int l) {
     for (int a=l-1;a>=0;a--)
     {
         if (alpha[a]=='z' && min<=max) {
                            alpha[a]='a';
                            index_z++; }
         else {
              temp=alpha[a];
              temp++;
              alpha[a]=temp;
              index_z=0;
              break; }
     }
     if (index_z==l) {
                     l++; }
     return l; 
     }
         
int main () {
    int len,val,last,check;
    double total=0E+0;
    ofstream outfile("random.txt");
    do {
        system("cls");
    cout << "min = ";
    cin >> min;
    cout << "max = ";
    cin >> max; } while(min>max || max==0);
    len=min;
    last=min;
    val=min;
    for (int i=min;i<=max;i++)
    {
    intialize_values(val);
    check=1;
    while (check==1) {
    for (int k=0;k<len;k++) {
        cout << alpha[k]; }
        cout << "\n";
    total++;
    len=increament(last);
    if (len>last) {
                  last++;
                  check=0;
                  val++; }
                  }
    }
    cout << "\n\n\n";
    cout << "Total Generated = " << total << endl;
    double ch=0E+0;
    for (int i=min;i<=max;i++) {  
    ch+=pow(26,i); }
    if (total==ch)
    cout << "\n\n" << "Task Completed Successfully.";
    cout << "\n\n\n\t\t\tpress any key to exit...";
    getch();
    return 0;
}
    
Thank you?
I'm pretty sure that could have been accomplished in 1/3 the code.
I'm pretty sure that could have been accomplished in 1/3 the code.


Yeah...
And also made more
a) Legible
b) Elegant.
This reminds me of that torrent some guy uploaded. It was was titled "how to hack" or something to that effect, and the contents included a file named ip.txt, which was the output of this program:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>

int main(){
	unsigned char a[5];
	memset(a,0,sizeof(a));
	while (1){
		int b;
		printf("%d.%d.%d.%d\n",a[0],a[1],a[2],a[3]);
		a[0]++;
		for (b=0;b<3;b++){
			if (!a[b])
				a[b+1]++;
			else
				break;
		}
		if (a[4])
			break;
	}
	return 0;
}


PS: jsmith wasn't too far off. I got it down to 24 lines. And the difference in size isn't negligible. It runs nearly 50 times faster. 2.48M iterations per second when redirecting output to a file.
Last edited on
Ashaming, that You did even download that torrent ^^...
Nobody can prove that.
Well, you must have searched something with one or more of the words in the title in it... so judging by your own approximation you were either searching for a how-to of some description, something to do with hacking, or both...

Edit: Your ISP probably could.

Also wouldn't it be faster to store the passwords in an array or vector and then print it all out in one go? Change writing to the disk to writing to memory (which is WAY faster unless you have an SSD)?
Last edited on
helios, thats a neat for loop.
I would have done it with nested for loops, but thats an inferior solution as increasing the string length requires adding another loop.

Your for loop method is a scalable method --- any thoughts on what kinds of problems your for loop method works on and when it doesnt ? Or maybe it always does ?
Well, you must have searched something with one or more of the words in the title in it... so judging by your own approximation you were either searching for a how-to of some description, something to do with hacking, or both...
Actually, I just read about it on /g/ or maybe /prog/.

Change writing to the disk to writing to memory
I believe you're not aware of the volumes of data being handled.
(Done with ls for the sake of dichotomy)
f:\>ls -lh 0.txt
----------+ 1 root None 2.4G 2010-06-26 10:52 0.txt

For the record, without producing any output, the speed is almost 300M comb./s. Fully processing an array of 6 elements took slightly less than a second. An array of 10 elements would take 5 days and six hours. Don't you love exponential explosion?

Your for loop method is a scalable method --- any thoughts on what kinds of problems your for loop method works on and when it doesnt ?
It's just the standard method for incrementing arbitrary precision numbers stored as arrays. It's the sum algorithm you learned in primary school with the right hand operand hard-coded to 1. All arbitrary precision libraries use similar logic internally.
Last edited on
Why would it be on /g/ or /prog/? Wouldn't it be on /t/ or /rs/?
It wasn't the main subject of the thread, just a passing comment. I think someone asked how to hack and someone replied with an equivalent program to the one above, and someone else might have mentioned the torrent.
helios wrote:
It's just the standard method for incrementing arbitrary precision numbers stored as arrays.

Yes, but I was curious on when a sequence of nested for loops can be mapped to one single for loop that can be "nesting depth extended" with just changing the variable values (as opposed to changinig code which nested for loops would require).
Ah, well. You reminded me of something I saw on /g/ yesterday, related to rms' interjection. The topic of discussion was Steve Jobs having AIDS.

AIDS, HIV/AIDS; Linux, GNU/Linux... you get the picture.
when a sequence of nested for loops can be mapped to one single for loop
Hmm... I think any nested series of loops can be transformed into a single loop. Look at this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
for (int a=0;a<x;a++){
	for (int b=0;b<y;b++){
		for (int c=0;c<z;z++){
			f();
		}
		g();
	}
	h();
}

//becomes

int index[4]={0};
int limits[4]={x,y,z};
function functions[3]={f,g,h};
while (1){
	functions[0]();
	index[0]++;
	for (int a=0;a<3;a++){
		if (index[a]==limits[a]){
			index[a]=0;
			functions[a+1]();
			index[a+1]++;
		}else
			break;
	}
	if (index[3])
		break;
}

//generalized:

std::vector<int> index,
	limits;
std::vector<function> functions;
//omitting initializations
while (1){
	functions[0]();
	index[0]++;
	for (int a=0;a<index.size()-1;a++){
		if (index[a]==limits[a]){
			index[a]=0;
			functions[a+1]();
			index[a+1]++;
		}else
			break;
	}
	if (index.back())
		break;
}
This can likewise be transformed into a recursive call stack.
Helios, nice :)
I'm copying that code over for future reference :D

BTW, I think line 14 should be int limits[4]={z,y,x}; ?
z is the fastest changing variable.
Last edited on
You're right.
You can also use a std::vector instead of the limits array.

This comes handy when you don't know the number of nested cycles in advance. If you however have an upper bound for the number of cycles, you can on the start allocate enough buffer in your std::vector to ensure that tiny extra speed optimization.

This is the technique with which I sustitute recursive calls in my heaviest computations.

Using recursion always leaves me a bad taste in the mouth, since it pushes all local variables on the stack, including those that have been introduced only to increase code readability and save an instruction or two of the processor.

Your "index" plays the same role as the stack in usual recursion.

[Edit:] although, when you think about it, accessing the stack should be quicker than dereferencing a vector (although I do not use a vector but my own data structure, which ensures me only one dereferencing operation+ the object derefencing operation). In other words, the extra overhead you pay for pushing things on the stack should pay off by the exrta instructions you save on derefencing your index and limits arrays.

Well, its all a matter of taste, after all. I do find avoiding recursion a bit more conceptual though: after all, that is exactly what your processor does anyways :)
Last edited on
[recursion] pushes all local variables on the stack, including those that have been introduced only to increase code readability and save an instruction or two of the processor.
Are you worried about how many recursion levels you have left? If not, then why do you care?
Pages: 12