I am new to coding. I am trying to solve crack problem of cs50. The problem works hashing 1 character, but when i try to hash 2 characters i can't pass arguments from the string to the crypt function. Please give me some advice about how to pass the argument to the crypt function. Thankyou!
#include <stdio.h>
#include <cs50.h>
#include <crypt.h>
#include <string.h>
int main(int argc, string argv[])
{
if(argc != 2)
{
printf("Enter the hash code as a single argument\n");
return 1;
}
string salt = get_string("Imput the salt\n");
string key[] = {
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "X", "Y", "Z", "a",
"b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "x", "y", "z"
};
char temp [40];
string hash = strcpy(temp, argv[1]);
for(int i=0; i<18; i++)
{
string cypher = crypt(key[i], salt);
int comp = strcmp(cypher, hash);
if(comp == 0)
{
printf("%s\n", key[i]);
break;
}
}
char char_2[7500];
for(int i = 0; i < 50; i++)
{
for(int j = 0; j < 50; j++)
{
sprintf(char_2, "%s%s", key[i], key[j]);
for(int m = 0; m < strlen(char_2); m++)
{
string cypher = crypt(char_2[m], salt);
int comp = strcmp(cypher, hash);
if(comp == 0)
{
printf("%s\n", key[i]);
break;
}
}
}
}
The error I recive are the following:
crack3.c:69:47: error: incompatible integer to pointer conversion
passing 'char' to parameter of type 'const char *'; take the address
with & [-Werror,-Wint-conversion] string cypher = crypt(char_3[m], salt);