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

int main(int argc, string argv[])
{
    if(argc > 2){ printf("too many arguments\n"); return 51; }
    if(argc < 2){ printf("too few arguments\n"); return 50; }
    //if(strlen(argv[1]) > 4){ printf("Password is greater than 4 characters\n"); return 52; }

    if(argc == 2) //make sure there are enough args
    {
        char hash_guess[] = "rofk";
        //long long counter = 0;

        //while(guess != argv[1]) //crypt(hash_guess, "50") != argv[1]) //while answer not correct
        //{
            for(int a = 65; a < 91; a++)
            {
                for(int b = 65; b < 91; b++)
                {
                    for(int c = 65; c < 91; c++)
                    {
                        for(int d = 65; d < 91; d++)
                        {
                            for(int A = 0; A < 9; A = A + 5) //control if first is caps or not
                            {
                                for(int B = 1 ; B < 9 ; B = B + 5)//control if second is caps or not
                                {
                                    for(int C = 2; C < 9; C = C + 5) //control if third is caps or not
                                    {
                                        for(int D = 3; D < 9; D = D + 5) //control if fourth is caps or not
                                        {
                                            hash_guess[0] = a;
                                            hash_guess[1] = b;
                                            hash_guess[2] = c;
                                            hash_guess[3] = d;
                                            hash_guess[A] = tolower(hash_guess[A]);
                                            hash_guess[B] = tolower(hash_guess[B]);
                                            hash_guess[C] = tolower(hash_guess[C]);
                                            hash_guess[D] = tolower(hash_guess[D]);
                                            printf("%s\n", hash_guess);

                                            string cryptoguess = (crypt(hash_guess, "50"));
                                            string input = argv[1];

                                            if( cryptoguess == input ) { return 0; }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            //}
        //}
        //string guess = crypt(hash_guess, "50");
        //printf("%lli", counter);
    }
    }
}

I'm trying to make a program that goes through every 4 letter word, starting on aaaa and going to ZZZZ. I got that part done.

Part of the assignment is to encrypt that, and if the encryption matches an encrypted password, then you know you "hacked" their password. When I compare the encrypted password that I manually enter and the one that comes up by using the crypt function, they are the same, but in the debugger I see this for when it is encrypted by the computer:

"0x7ffff7dd9200 <_ufc_foobar+131200> "50k72iioeOiJU""

and the normal one that I enter shows

"0x7fffffffe34f "50k72iioeOiJU""

the same thing without the _ufc_foobar. Does anyone know why that is there and how I can get rid of it?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
sruly
  • 115
  • 9

2 Answers2

1

<_ufc_foobar+131200> isn't part of the string. It's your debugger attempting to figure out where the string came from, and assign a name to it. In this case, it's come up with a bogus result -- _ufc_foobar is the name of a function or variable somewhere else in the program, and your string happens to be stored 131,200 bytes (about 128 KB) after that in memory.

You can safely ignore this. Your strings are equal. They just happen to be stored in different parts of memory (which is normal).

1

The weird junk you are seeing is visualization of offsets of memory addresses in your code which can be ignored.

In your code you are using string when GNU specifies char * is the result of the crypt function.

Therefore, you cannot compare the pointers to the char array using == but instead need to use strcmp C comparing pointers (with chars)

For crypt see: http://www.gnu.org/software/libc/manual/html_node/crypt.html

Alexander Higgins
  • 6,765
  • 1
  • 23
  • 41