0

I am badly struck at the Crack problem in pset2.

I have an idea which uses 5 for loops, to check for all the possible variations of the alphabets. Considering a case where the password is only of upper case, here's an example of the loops combining to give all possible variations of the alphabets. I can't get this to work. Please help!

 char password[5];
for (int i=0; i<26; i++)
{
    password[0] = i;
    for (int j=0; j<26; j++)
    {
        password[1] = j;
        for (int k=0; k<26; k++)
        {
            password[2] = k;
            for (int l=0; l<26; l++)
            {
                password[3] = l;
                for (int m=0; m<26; m++)
                {
                    password[4] = m;
                    for (int n=0; n<5; n++)
                    {
                        password[n] += 'A';
                    }
                    printf("%s\n",password);
                    sleep(1);
                }

            }
        }
    }
}

1 Answer 1

0

Shot in the dark. Where's the end of string marker that's supposed to be at password[5] (and password[] should be one char longer to allow for it).

You could also do password[0] = i+'A'; and similar for each loop and eliminate the innermost loop.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

1
  • Appending the array with \0 doesn't make any changes. From what I gather, the innermost loop to convert the value from 0 to ASCII[A] is what's causing the problem. I was able to successfully execute the program by changing all the loops to look something like this for (char i = 'A'; i < 'z'; i++) Commented Mar 1, 2018 at 9:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .