0

So I've been stuck on crack.c for two weeks now (not literally - I have a full time job too ha) and on top of having 50 questions about it, I just can't get my head round the solution!

Basically I have cheated a little bit (otherwise I will stuck at this question for ever) and have looked at a few different codes on stackexchange. I've seen quite a lot of people using the strcmp() function but I haven't seen/heard of it before. I'm wondering if this is necessary to crack the password.

OTHER CONFUSIONS:

I understand the crypt() function and how it works with the key and salt parameters. And based on my logic I vaguely figured out that we have to figure out the password by using brute force attack (but specs ask us to solve it as quickly as possible but this is about the only way I can think of? Help :( )

So my logic goes:

  1. Declare an array of 52 characters (a-z, A-Z) - is there a more efficient way to do so? Perhaps using a for loop.

    char alpha [52] = {'a', 'b', ...'z', 'A', 'B',...'Z');
    
  2. Somehow iterate over the above array for 52 times using for loop (int i being the counter variable.

    for (int i=0; i<52; i++)
    
  3. Somehow (?) assign the first two characters of the given hash to char salt [2]. I'm sure the way I do it is not how it should work..

    char salt [2] = {hash[0], hash[1]};
    
  4. Create a function that uses crypt() to hash each character, taking the parameters of alpha [i] and salt and see if it matches the given hash. And if so, prints the character.

    char x = crypt(alpha[i], salt);
    if (x==hash[?])
    {
    printf("%c", x);
    }
    

So my other questions are, 1. how can I match if the hash is actually 13 characters long? 2. Also, wouldn't this method takes ages? 3. Zamyla mentions about creating an array of up to 5 bits for the output password (last bit being \0). I sort of get this and have a vague idea of using a loop to do it. Am I making sense?

Thanks a lot and, as usual, if you're stuck in this question like me and happen to live in London, I'm more than happy to meet up over the weekend and discuss. Coding alone is a torture........

3
  • Your salt should have three characters, last one being null terminator. crypt probably returns a char*, not char. Strings cannot be compared with == as they are really just pointers to characters, that would not compare the characters! – Blauelf Jun 1 '17 at 16:05
  • What exactly does char * mean? – Pamela Inácio Jun 1 '17 at 16:52
  • char* means pointer to char, and is how you reference a string, as a pointer to its first character. An array in C is basically a pointer, if you declare it like char salt[3] with some space allocated on stack, and the pointer is pointing to the beginning of that memory block. – Blauelf Jun 2 '17 at 8:54

You must log in to answer this question.

Browse other questions tagged .