hey guys, problems with a program

i'm having a problem with a program intended to "crack passwords" but not really.. this will never be implemented, i just thought it'd be a cool project to get to know c++.

how it works:
it recognizes 93 chars (93 because that's the number of special chars and letters you would expect to find in a simple-ish password)

it finds total number of possible password combinations based on the formula
93^length of the password

then, by using a for loop, it counts up from 0 to the number of combinations possible.

inside that for loop is another for loop that sets the value of each node of the array by iterating through and using this thought

array[0] will equal number/(93^length)

array[i] will equal (number%(93^length)/(93^(length-i)))

the problem: the output isn't even giving me a value after the first node in the array, it's only working correctly for the first node

i know this method works, but maybe my syntax is messed up. i've tinkered for hours with no solution. please help :)

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
#include <iostream>
#include <string>
#include <array>
#include <cmath>
using namespace std;

int main(){
	int* passArray2 = NULL;  
	int number, numRemain, findRemain, length;
	double percentDone;
	double availChars = 93;
	cout << "Enter the length of the password: ";
	cin >> length;
	passArray2 = new int[length];
	for(int z = 0; z < length; z++){
		passArray2[z] =0;
	}
	double possible = pow(availChars,length);
	for(number = 0; number <= possible; number ++){
		percentDone = 100*number/possible;
		cout<< endl;
		for(int i = 0; i < length; i++){
			findRemain = pow(availChars,(length-(i+1)));
			numRemain = number % findRemain;
			if(i==0){

				passArray2[i] = number/findRemain;
				cout << passArray2[i];
			}else{
				passArray2[i] = numRemain/findRemain;
				cout << passArray2[i];
			}
			
		}
		cout << "    " << percentDone << "%" << endl;
		//system("pause");
	}
	system("pause");
}


and i realize that my code is very sloppy right now. that's what happens when you change every little thing for a couple hours haha

thanks for any help!
if my description is ambiguous/vague to you in any way, please let me know and i'll do my best to clearify
You do realize that even a short, 6 digit password, will have over half a trillion possibilities?
Testing every one would take a very long time. I suggest limiting yourself to the either numbers 0-9 or the standard English alphabet.
haha of course i realize, but it's just a tinkering project. i just want it to work correctly for the sake of working correctly. and who knows? maybe if i have a 10 digit password and a decade to crack it, this might come in handy ;)

that being said, do you actually have any suggestions?
maybe to help you understand this, it works on the same principle as a simple stop watch, by taking the remainder of the largest spot, and then seeing if each consecutive smaller spot will divide, and then taking the remainder of that to the next smallest spot.

the thing throwing the whole kink in it is that the length is a variable, and it's making it hard to wrap my head around it.
Last edited on
I have a few small suggestions:
1. Refrain from using system() commands whenever possible. One alternative to system("pause") is std::cin.get()
2. Output is very slow. Instead of outputting %done every iteration of the loop, do it at intervals of 1.
3. line 19 should be number < possible. Remeber that 0 counts as a number too.
4. Move lines 28 and 31 outside the if statement, because they are always executed whether or not the statement is true. Also, output here will arain be time consuming. Do you really need to see every possible password?
5. Why not use strings rather than char arrays? It will make certain things easier.
6. There is an easier way to get each possible password.
7. I don't think you need lines 15-17 at all.
8. availchars should be declared as a constant
Last edited on
thank you for the suggestions

i definitely see what you're saying with the % done.

concerning your 3rd suggestion, if i didn't set it to <= it wouldn't reach the very last number for some reason? maybe you know why? it wouldn't finish 100% which i thought was weird, but i just kinda rolled with it.

lines 28 and 31 are definitely not efficient, but i put them there to see if it would output any differently and maybe give me some insight into where my problem is.

15-17 was just a fruitless attempt at making this code work :) it's about to get deleted haha

i was planning on setting options after i got this core bit of code done to where you could narrow down which characters the password would contain based on the type, so that's why i had availChars set as a variable. but i should just try to simplify this as much as possible though.

and what's the easiest way to get each possible password?

i'm a C++ newbie, so thank you so much for your reply and suggestions. your feedback is much appreciated!
oh, i finally got this resolved. i had to add another if statement and make some modifications to make findRemain calculation more dynamic (shoulda known ) -_-

i also added a couple things. one, because of your suggestion about reducing outputs to speed up the program. i made it to where it would dynamically change output intervals based on how long the password might be, and how relevant speed was.

and regarding your first post, i also added some code that allows the program to predict how much longer the guessing will take, and for a 10 digit password that just used characters a-z (not including lower-case), it would take ~26 years haha. but anything under about 7 could be found fairly quickly, so i'm going to try to optimize this code, and see how that affects the time it takes.

thanks again, man.
Topic archived. No new replies allowed.