Question

I am just coding some classic brute force password cracking program, just to improve myself.

I've explained how my program works at the start of the code. Check some of those screenshots to understand easier.

My program works really well but it's a bit dirty and it can be faster if I solve this problems;

I've got two problems,

1-) My code looks so long and dirty because I copied a code block 8 times in a switch case statement. For example case 1 loops with one character length passwords. case 2 = two characters, case 8 = 8 characters length password. The one and only difference between those cases is the "for loop" count, case 1 got 1 for loop, case 8 got 8 nested for loops. I want to make my code prettier, so how can I get rid of this copy&paste code and make it 1/8 size of current size. CTRL + MOUSE WHEEL DOWN , zoom-out and see the copy pasted parts.

2-) It tries 1 digits first, then 2 digits, then 3 digits and so on. So it should wait for 1,2,3 to get the 4 digit ones. And it makes the program lose so much time at higher digits. My CPU i7 3770k got 6 cores, program runs only with one I guess because it says %13 CPU usage. I want to make it higher like 6 cores on the same task OR each core will take care of one part like first core will start looping only 8 character length ones, and second core will do the same with 7 character length ones... and when one of them finds the answer, program will end. Can we really do it?

Code is too long as I said, so I don't put it here,

Here is the code: http://pastebin.com/ZT373674/

I hope I explained good, thank you for helping from now!

Was it helpful?

Solution

With regard to the 8 times duplicated code, factor out the duplicated code into a function. Then, call the function from within each case. Pass the number of repetitions for the loop into the function as an argument.

With regard to the multithreading, yes, you could dispatch to multiple threads and make it faster, but that will make your coding much more complex and bug prone. If you really want to pursue that, it would be better to find a good book on it, or search for previously answered questions on writing multithreaded code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top