0

I've been scratching my head at this for the better part of a day now:

When I try to save the salt in a separate string called salt using the first and second characters of the second element of argv[], it comes back with 50, which is correct, and then most of the time 1 or 2 random characters will follow, even though I've specified the string length of salt to be 2.

I have used eprintf to see what the values are, and as you can see below, when I use eprintf("User salt is: %c%c\n", argv[1][0], argv[1][1]); straight away, the salt comes back correct, but when I use char salt[2] = {argv[1][0], argv[1][1]};, there is an extra tT after my salt of 50.

// Get the hashed password
int main(int argc, string argv[])
{
    // Only 2 words should be entered at the command-line
    if (argc == 2)
    {
        // Take the hashed password

        // Get the salt: the "salt" is the first 2 characters of the hashed keyword
        char salt[2] = {argv[1][0], argv[1][1]};
        eprintf("User hash is: %s\n", argv[1]);
        eprintf("User salt is: %c%c\n", argv[1][0], argv[1][1]);

        eprintf("Current salt string is: %s\n", salt);

Terminal:

~/workspace/pset2/crack/ $ ./crack 50JGnXUgaafgc
crack.c:19: User hash is: 50JGnXUgaafgc
crack.c:20: User salt is: 50
crack.c:22: Current salt string is: 50ؓtT
crack.c:33: Hash with current salt is: sawJaWbek0YZw
~/workspace/pset2/crack/ $ 

Any help would be very much appreciated!

1

Where's the end of string marker \0?

printf will keep printing whatever follows in memory until it sees the EOS marker, even into other areas of memory.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

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