I'm trying to make pset2 crack but having so much problems and my head is about to explode. Here is my code; my first error is on line 41. I never get to pass a value to the key for crypt. I'm very needed for help.
#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <string.h>
#include <crypt.h>
#include <unistd.h>
#define _XOPEN_SOURCE
char* crypt (const char *key, const char *salt);
int main (int argc, string argv[])
{
// Check if only 2 arguments
if (argc != 2)
{
printf("Insert only one hash\n");
return 1;
}
// Creacion d variable para asignarle el valor del hash
string hash = argv[1];
char salt[] = {hash[0], hash[1], '\0'};
printf ("Hash is: %s\n", hash);
printf ("Salt is: %s\n", salt);
// Creacion del loop para interactuar con el hash.
// Creacion de array para almacenar los caracteres q se iran crakeando.
// Creacion de variable para almacenar el valor q devuelva crypt function
char alpha[] = {"abcdefghijklmnopqrstuvwxyz"};
string cnum;
for (int i = 0, n = strlen(hash); i < n; i ++)
{
for (int j = 0; j < 26; j++)
{
// Check si min o mayusc
if (islower(hash[i]))
{
tolower(alpha[j]);
cnum = crypt(alpha[j], salt);
if (cnum == hash[i])
{
break;
}
}
else
{
toupper(alpha[j]);
cnum = crypt(alpha[j], salt);
if (cnum == hash[i])
{
break;
}
}
}
printf ("%c", cnum);
}
}
errors when compiling are:
crack.c:41:30: error: incompatible integer to pointer conversion passing 'char' to parameter of type 'const char *'; take the address with &
[-Werror,-Wint-conversion]
cnum = crypt(alpha[j], salt);
^~~~~~~~
&
crack.c:9:26: note: passing argument to parameter 'key' here
char* crypt (const char *key, const char *salt);
^
crack.c:42:26: error: comparison between pointer and integer ('string' (aka 'char *') and 'int') [-Werror]
if (cnum == hash[i])
~~~~ ^ ~~~~~~~
crack.c:50:30: error: incompatible integer to pointer conversion passing 'char' to parameter of type 'const char *'; take the address with &
[-Werror,-Wint-conversion]
cnum = crypt(alpha[j], salt);
^~~~~~~~
&
crack.c:9:26: note: passing argument to parameter 'key' here
char* crypt (const char *key, const char *salt);
^
crack.c:51:26: error: comparison between pointer and integer ('string' (aka 'char *') and 'int') [-Werror]
if (cnum == hash[i])
~~~~ ^ ~~~~~~~
crack.c:57:23: error: format specifies type 'int' but the argument has type 'string' (aka 'char *') [-Werror,-Wformat]
printf ("%c", cnum);
~~ ^~~~
%s
5 errors generated.
make: *** [crack] Error 1
Killed
.