0

Here's the program:

#define _XOPEN_SOURCE
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <cs50.h>

int main()
{
    string salt = "50";
    string test;
    string crack = GetString();
    string hash;

    char a = "";

    for(int i = 97; i <= 123; i++)
    {
      char b = "";
      for(int j = 97; j <= 123; j++)
      {
        char c = "";
        for(int k = 97; k <= 123; j++)
        {
          char d = "";
          for(int l = 97; l <= 123; j++)
          {
            test = (a + b + c + d);
            hash = crypt(test, salt);
            if (strcmp(hash, crack))
            {
              printf("%s", test);
              exit(0);
            }
            d = (char)l;
          }
          c = (char)k;
        }
        b = (char)j;
      }
      a = (char)i;
    }

}

I compiled it using "gcc -o crack crack.c -lcrypt -lcs50".

How do I fix it? I'm kinda new to this. xD

Thanks in advance!

1

In C, strings are arrays of char. You assign a string to a char variable, maybe you meant '\0' (string terminator) instead of "" (empty string).

You cannot add them to concatenate, you'd have to build your own string, like for example

char test[5];
test[0] = d;
test[1] = c;
test[2] = b;
test[3] = a;
test[4] = '\0';

Last character is the null terminator, which marks the string end.

You must log in to answer this question.

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