0

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);
0

EDIT 2:

You have an array of pointers, I would use

char * dictionary = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
char key[12];    //to copy the characters

To use a single character we can do:  

key [1] = '\0';
     //for loop
         key [0] = dictionary [i];

keep in mind that string key[52] is an array of pointers

2
  • If i would use ‘A’ i would not be able to pass it to crypt. – Criticalll Aug 18 '19 at 21:45
  • then use char* dictionary = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; – MARS Aug 18 '19 at 21:56

You must log in to answer this question.

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