I just started on the crack problem and wanted to ask a quick preliminary question about understanding the crypt function. Here is my code:

#include <cs50.h>
#include <stdio.h>
#include <crypt.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

int main(int argc, string argv[])
    if (argc!=2)
        return 1;
        const char *key = argv[1];
        const char *salt = "ab";

        string s = crypt(key, salt);

this isn't really a prototype for the actual program; I just wanted to understand correctly what crack does. However, when I enter the key "LOL" the hash it returns (without the salt) is 4drpR3wWBqU. But shouldn't it be cI2vYkF0YU2 per the example in the hint? Am I misunderstanding what the output of crack should be?


1 Answer 1


A couple of things, if your if condition returns 1 in case of error you don't need an else clause, this only complicates the code. In addition you should print the correct way to use the program, a simple error message can lead to confusion for the user:

printf ("usage: ./crack <string> \ n");

or something similar.

By the way to get the hash of the example you should use salt "50":

const char *salt = "50";
  • Oh I see, for some reason I just didn't realize that the salt would change the DES algorithm's output... thanks so much!
    – hli
    Aug 20, 2019 at 15:52

You must log in to answer this question.

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