Hot answers tagged

14

Less Comfy Man Page NAME crypt - password and data encryption SYNOPSIS #define _XOPEN_SOURCE #include <unistd.h> string crypt (key, salt); DESCRIPTION key is a user's typed password. salt is a two-character string chosen from the set [a-zA-Z0-9./]. This string is used to perturb the algorithm in one ...


14

Just imagine one day you get a "hashed password" that could be used to log into your girlfriend's email, what will you do? Is it possible to log into the email with that "hashed password"? Of course, NO, because the "hashed" (or "encrypted") password contains non-sense characters. Typing that encrypted string into the log-in window will lead to the error ...


6

Your problem is that letters[i] is a char, but the crypt() function expects a char * (string) as its first argument. So what you really want to do is pass a string with a single character, not a single character. You need to pass this char array ['a', '\0'], not this char 'a'. A simple fix can be to declare a char array with a length of 2, with the second ...


6

crypt() is an encryption algorithm. It takes a plaintext string (a user password), and encrypts it, so that it can be stored in a file. char *crypt(const char *key, const char *salt) The key argument is the password to be encrypted, and salt is a two character string that 'tweaks' the algorithm's output. The output is a 13 character string. The first ...


4

If you read the man page of the crypt function it says in one point: The return value points to static data whose content is overwritten by each call. So the first time you call crypt, and assign its return value (which is a pointer to a string) to the coded variable, the coded variable contains the correct encrypted password. But ...


4

Whether crypt function uses DES or MD5-based algorithm is determined by what salt argument you pass to it. If the salt you pass consists of 2 alphanumeric characters, the function uses DES algorithm. You can read more about it here: http://www.gnu.org/software/libc/manual/html_node/crypt.html Try it out in your program, just don't forget to include crypt.h ...


4

Answered by an instructor on reddit. here:https://www.reddit.com/r/cs50/comments/9o3eg8/pset2_crack_is_taking_a_lot_of_time/


3

string is defined in cs50.h as an alias for char *. string s = "word"; declares a pointer to char named s and lets it point to the string constant "word". You could use an array instead, like char s[] = "word";, which is like char s[5] = "word";, creating an array of 5 characters and initialising it to the content of "word", four letters plus a null ...


3

For instance, the brute force search will at some point generate the same character sequences as in the dictionary, but how would the program know to avoid re-checking these same values without searching the dictionary? Maybe you should store the words read from the dictionary and tested in a string array, then when you get to your brute-force ...


3

Your problem is probably because of this line: char salt[2] = "50"; If you recall, you have to end a string with an additional character, the null zero '\0', so technically salt is 3 characters long. Change it to char salt[3] = "50"; or even better: char salt[] = "50"; Edit working code (yours actually, after some small modifications) #define ...


3

You should use strcmp, not "==" when comparing two strings in c. The strcmp function, included in string.h takes in two parameters, your two strings, and outputs 0 if the strings are equal. If you need more info, check it out on cs50 reference. Therefore, the problem lies in: if (result == hash) Hope this helped!


3

You went down the rabbit hole with this pset. You chose the wrong path at the fork on the road. Just think for a minute how mush you will have to change, if instead of 5 letters which is the current maximum length of passwords, it was changed to 6! You should definitely rethink your solution (if you have finished all psets I think you have what it takes now)...


2

First consider the size this elements have in the cs50 appliance. char = 1byte char* (pointer) = 4bytes You are declaring word and initializing it with the pointer returned by malloc, that is fine. But you are allocating: malloc(sizeof(char*) * 1); You need to realize that the sizeof(char*) is the size of a pointer, which is 4bytes in the cs50 appliance, ...


2

The salt is used to influence the encryption process. If you call crypt twice on the same key passing in different salt each time, you'll get different hashes (results). The salt can be any two characters, each of which is in the set [./0-9A-Za-z]. That's a total of 64 characters. This means that you can have 64^2 possible combinations of 2-character salts ...


2

It will work when constructed as in the man page. From man feature_test_macros: NOTE: In order to be effective, a feature test macro must be defined before including any header files. This can be done either in the compilation command (cc -DMACRO=value) or by defining the macro within the source code before including any ...


2

So I'm wondering if submitting a program that would work but can't be actually tested is okay and is what is expected from us It is expected of you to find all the plaintext passwords of the hashed passwords. Your program should terminate in a reasonable amount of time. You can try to crack as many passwords as you want. By the way, I'm wondering... Is ...


2

One way would be to interpret characters 'a' to 'z' as digits in a number with base 26, start at "aaaa" (representing 0), and then adding 1 to the last string. Add or subtract 'a' for conversion between character and "digit" value. Instead of storing the string as your state, you could also store the values, and convert to the string for passing to crypt ...


2

Let's take a look at the man page of strcat(): char *strcat(char *dest, const char *src); The strcat() function appends the src string to the dest string, overwriting the terminating null byte ('\0') at the end of dest, and adds a terminating null byte. So, it seems that strcat() doesn't just return to you a new string with the result of the ...


2

The var cracked is essentially a pointer, holding the address of the start of a string. if(cracked == argv[1]) is comparing a string's address to the address of argv[1], another string. Next, strings cannot be compared with the == operator, although addresses can. You should get to know the strcmp() function and it's cousins. They will be most helpful to ...


2

I believe this has something to do with the <= in your for loop. You would iterate 53 instead of 52 times, allowing s[0] = alpha [53] which would be out of range thus causing a segmentation error. I believe that you can apply this to other parts of your code aswell. Instead, < symbol instead of <=. Also, take a look at the other answer given by ...


2

This is because when you reach the innermost loop for the first time, your array is already four characters. Now for all the permutations you will have four characters in the array. This is the reason it works only with four character hashed passwords. Only if the password was 'a' or 'aa' or 'aaa' would it work. I tried to make it work using four different ...


2

In C a string name is just a pointer to the actual string located somewhere in memory ending with a NULL character. So when you use the "==" operator to check it's equality you are basically comparing the pointers (the memory address it's pointing to). But the strcmp() function takes in two 'pointers to string' (the name of string) as parameters and ...


2

Strings in C are pointers to char, pointing to the first character in the string, so the value you compared is a memory address. To compare strings by content rather than by address, use the strcmp function. And there's no need for specifying an explicit null terminator in a string literal, as it contains an implicit one, but using a list of char (salt2), it'...


2

There's a couple of things that I can see won't work: string unhashed = capsPattern(wordsArray[i], "1011"); I can't see how this will work as you're expecting, as wordsArray[i] is just character i from wordsArray i.e. you're only sending a single character to the function capsPattern() when it is expecting a char array. Just changing this to wordsArray ...


2

I have used recursion, wrapped inside one loop for the number of digits. Which I think is the same approach mentioned by User20025. The recursion concept is that a 3 letter password is 1 letter plus a 2 letter password. The whole thing finds the password for Malan (NOPE) in 15 seconds in the IDE50. The max loop (ZZZZ) is done in 25 seconds.


2

From the man page for crypt: (under Description) The return value points to static data whose content is overwritten by each call. This means that each time you call crypt it encrypts the key using salt and stores the result in a specific (static) memory location. The return value is actually a pointer to that value, not the value itself. In the ...


2

Other than the exact letters that are in it, it's no different from the others. I'll give you the hint that the first letter is 'A' Maybe your algorithm is somehow skipping that?


2

You seem to have some misunderstanding about the crypt function. crypt takes 2 arguments, a string (like "abcd") and a salt (like "50"). You appear to be trying to compare individual chars. The idea here is that you are given a hash and you need to try all combinations of 1,2,3,4 & 5 letter long strings to try to find the password that matches the ...


2

I did it in two ways. First was recursive, depth-first search. Can also be implemented breadth-first. I called my recursive function with a pointer to the memory to use, an index (initially 0) and a maximum password length, and the reference hash. In case of depth-first, I place '\0' at the index and hash the string, comparing it to the reference hash. ...


2

It doesn't work for 5 characters because you haven't allocated enough space for a 5-char string with char word[5]; Remember the null char! As a consequence, when you set word = {'a', 'a', 'a', 'a', 'a'} and then use that with crypt, crypt will be expecting a string so it may not be "aaaa" but "aaaaaxyz" where x,y,z happen to be the next bytes of memory ...


Only top voted, non community-wiki answers of a minimum length are eligible