Skip to main content
added 8 characters in body
Source Link
sinister
  • 3.5k
  • 2
  • 20
  • 37

char word[9]; word[8] = '\n';

char word[9]; 
word[8] = '\n';

for(int a =64; a < 123; a++)
{
    word[0] = a;
    for(int b =64; b < 123; b++)
        {
                word[1] = b; 
        for(int c =64; c < 123; c++)
            {
                    word[2] = c;
            for(int d =64; d < 123; d++)
                {
                        word[3] = d;
                for(int e =64; e < 123; e++)
                    {
                            word[4] = e;
                    for(int f =64; f < 123; f++)
                        {
                                word[5] = f;
                        for(int g =64; g < 123; g++)
                            {
                                    word[6] = g;
                            for(int h =64; h < 123; h++)
                                {
                                        word[7] = h;
                                        //do something with the word.
                                }

                            }

                        }

                    }

                }

            }

        }
}

char word[9]; word[8] = '\n';

for(int a =64; a < 123; a++)
{
    word[0] = a;
    for(int b =64; b < 123; b++)
        {
                word[1] = b; 
        for(int c =64; c < 123; c++)
            {
                    word[2] = c;
            for(int d =64; d < 123; d++)
                {
                        word[3] = d;
                for(int e =64; e < 123; e++)
                    {
                            word[4] = e;
                    for(int f =64; f < 123; f++)
                        {
                                word[5] = f;
                        for(int g =64; g < 123; g++)
                            {
                                    word[6] = g;
                            for(int h =64; h < 123; h++)
                                {
                                        word[7] = h;
                                        //do something with the word.
                                }

                            }

                        }

                    }

                }

            }

        }
}
char word[9]; 
word[8] = '\n';

for(int a =64; a < 123; a++)
{
    word[0] = a;
    for(int b =64; b < 123; b++)
        {
                word[1] = b; 
        for(int c =64; c < 123; c++)
            {
                    word[2] = c;
            for(int d =64; d < 123; d++)
                {
                        word[3] = d;
                for(int e =64; e < 123; e++)
                    {
                            word[4] = e;
                    for(int f =64; f < 123; f++)
                        {
                                word[5] = f;
                        for(int g =64; g < 123; g++)
                            {
                                    word[6] = g;
                            for(int h =64; h < 123; h++)
                                {
                                        word[7] = h;
                                        //do something with the word.
                                }

                            }

                        }

                    }

                }

            }

        }
}
Source Link
Milan
  • 55
  • 7

algorithm for brute force pset2 hacker edition

I am doing PSET2 "Hacker Edition". I did used dictonary and It worked fine for cracking some passwords.I want to generate all the possible characters in incrementing order but I am unable to think the right algorithm. My code is:

char word[9]; word[8] = '\n';

for(int a =64; a < 123; a++)
{
    word[0] = a;
    for(int b =64; b < 123; b++)
        {
                word[1] = b; 
        for(int c =64; c < 123; c++)
            {
                    word[2] = c;
            for(int d =64; d < 123; d++)
                {
                        word[3] = d;
                for(int e =64; e < 123; e++)
                    {
                            word[4] = e;
                    for(int f =64; f < 123; f++)
                        {
                                word[5] = f;
                        for(int g =64; g < 123; g++)
                            {
                                    word[6] = g;
                            for(int h =64; h < 123; h++)
                                {
                                        word[7] = h;
                                        //do something with the word.
                                }

                            }

                        }

                    }

                }

            }

        }
}

The problem is my code only works for fixed sized password(as many as the no of loops) in this case 8. Also it seems that I am repeating same code many times thus making the code ugly and dirty. Please help me, maybe with some pseudocode.