brute force attack. need help with this assigment

create a program that will do a brute force attack to crack passwords. program should ask user for a password and program should fin the password. experiment with different sizes, maximum of 4 characters. try passwords with numbers and letters of alphabet in both lower and upper case.

also calculate how long it takes to crack a password.
function difftime(then, now) in <ctime.h> library may be used
So what have you done so far?

Which aspect of the assignment, specifically, are you having trouble with?
i have no idea at all.
We're not going to do your homework for you.

If this is genuinely an assignment you've been given, then you must have had some kind of teaching on how to write a simple C++ program, to the point where your teacher thinks you're able to handle this assignment.

Think about it. Imagine the steps you might have to go through to do crack a password. Then start trying to write the code to achieve those steps. When you hit a specific problem, then post your code here, explain the problem, and we'll help.

you have several hints like

i need to use a function that calculate the time

maximum of 4 characters ( string size is 4 , right?)

try with numbers ( 0-9 and max is 9999 right? ( 4 digits remember...))

letters of alphabet( a,b,c,...z) right?

and capitals ( toupper(character) ?)

that should be enough I think

come up with something and we see if you are getting it, then.
Thanks for that. But I knew that already. I just don't know how to put it in code. Anyways thanks for trying to help

ask password
myPassword = userAnswer

time0 = libraryIhaveIncluded.getTime()

for ( character = 0 to 3 )
{
// brute force means try them all

for( number=0 to 9 )
{
if ( myPassword[ character ] == number)
//move to the next character
character ++
}

for ( letter = 'a' to 'z' )
{
if ( myPassword[ character ] == letter || myPassword[ character ] == toupper( letter )
character ++
}
}

time1 = libraryIhaveIncluded.getTime()

totalDuration = time1 - time0

print the password

print the time

smile

.

Something like that should help I guess...
> experiment with different sizes, maximum of 4 characters
> passwords with numbers and letters of alphabet in both lower and upper case.

Each character could be any one of 62 possibilities (26 lower case + 26 upper case + 10 digits)
If we have a password of four characters, the number of possibilities are 62 * 62 * 62 * 62 == 14776336
Brute force implies that these should be generated one by one till a match is found.

With a crude nested loop construct:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>

int main()
{
    const std::string pword = "Z2bw" ; 
    const std::string alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" ;

    unsigned long long n_attempt = 0 ;
    for( char first : alphabet ) for( char second : alphabet ) for( char third : alphabet )  for( char fourth : alphabet )
    {
        ++n_attempt ;
        if( pword == std::string{ first, second, third, fourth } )
        {
            std::cout << "found it at attempt# " << n_attempt << '\n' ;
            return 0 ;
        }
    }
}

http://coliru.stacked-crooked.com/a/da731830744e66a0
thanks all. its really helpful
Topic archived. No new replies allowed.