1

Probably a silly question, but please bear with me as I'm pretty new to this.

I'm stuck with Crack in Pset2. Can't wrap my head around how to go about iterating through all combinations of alphabet.

All big and small alphabetical characters are loaded to array alpha (to leave out all non-alphabetical ones) and I want to be loading their combinations to array pass that is then encrypted, and the hash is then compared with the given hash coded. It works for one letter passwords with the below code, and I just can't figure out how to take it to 4 character pass. Would appreciate any direction or hint. I tried with nested for functions but that didn't work for pass shorter than 4 characters.

int check, a;

for ( a = 0; a < 56; a++)
{
    pass[0] = alpha[a];
    pass[1] = '\0';

    check = strcmp(coded, crypt(pass,salt));

    if ( check == 0 )
    {
        printf("%s\n", pass);
        return 0;
    }
}
2
  • even though its a lot of code i just created a nested for loop for each 1,2,3,4 digit passwords. – masterseeker Mar 27 '17 at 22:17
  • Thanks @masterseeker That's what I ended up doing in the end, but have a feeling there should be a more elegant way. Never mind, submitted already. – Brano J. Svac Apr 5 '17 at 1:26
-1

You can just make a list of all the letters you can use and do someting like a

string letters = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
// Get some information or whatever.
for (int a = 0; a < len(letters) /* Something that returns the length of a string. */; a++)
{
    for (int b = 0; b < len(letters); b++)
    {
        for (int c = 0; c < len(letters); c++)
        {
            for (int d = 0; d < len(letters); d++)
            {
                for (int e = 0; e < len(letters); e++)
                {
                    // Do whatever.
                }
            }
        }
    }
}
// Continue with your business.

That's what I basically did. (With only like 15 lines of looping.)

You must log in to answer this question.

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