0

So just to make sure im not just completely confusing myself, I wanted to make sure I understood the crypt function.

So I have some simple code:

#define _XOPEN_SOURCE
#include <cs50.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
const int MAX_SIZE = 4;
const int SALT_LENGTH = 2;
const int WORD_MAX = 128;

int main(int argc, string argv[])
{

    if (argc != 2){
        printf("Usage: ./crack hash");
        return 1;
    }
    char *cipher = argv[1]; //cipher 
    char *pass = "caesar";
    char *salty = "50";
    char *stuff;

    stuff = crypt(pass,salty);
    for(int a = 0;a < strlen(stuff);a++)
    {
        printf("%c",stuff[a]);
    }

    if(strcmp(stuff, cipher) == 0)
    {
        printf("YAY");
    }
return 0;
}

So I know (From the CS50 website that the salt being used is 50 (since it's always listed first in the encrypted password) and I know on the CS50 site "caesar" is "50zPJlUFIYY0o" according to the 2016 page

So how come when I run this, I get something completely different?

50psJDBxuKJdQ

Is what I get?

I mean I must be missing something here, obviously this isn't even close to the "full code" but if I can't even get the crypt function "using" right Im probably gonna struggle on the rest.

Any ideas?

1

I presume you are referring to the following passage:

andi:HALRCq0IBXEPM
caesar:50zPJlUFIYY0o
eli:50MxVjGD7EfY6
hdan:50z2Htq2DN2qs
jason:50CMVwEqJXRUY
...

The confusion here is that this is not a list of words and their crypt() equivalents, this is the contents of a sample file /etc/passwd where the first item is a username and the second is an encrypted password. The encryption you are expecting for caesar is actually the encryption for caesar's password and indeed, the whole point of the exercise is to crack these passwords!

And just so you know, you are using crypt() correctly. Try putting 12345 in and see if you get 50Bpa7n/23iug, as per the spec.

3
  • AH I thought the first word was the actually "password" and the second was the encrypted portion. I was so confused at what I was doing wrong. So....how would I even go about checking that im right then? Since the passage doesn't actually list what the encrypted password actually is in plain-text?
    – msmith1114
    Jan 29 '17 at 19:34
  • There is an example in the spec, it gives you the encryption for 12345, which is 50Bpa7n/23iug. Try putting this into your crypt() function and see what you get. Jan 29 '17 at 21:49
  • Thanks, I was def. confused when I saw the beginning "username" I had assumed that was the passcode.
    – msmith1114
    Jan 30 '17 at 4:16

You must log in to answer this question.

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