Skip to main content
14 votes

Not able to understand what I need to do in pset2 (crack.c)

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, ...
TrungNguyen's user avatar
6 votes
Accepted

Crack - launching and crypt function

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 ...
robert_x44's user avatar
6 votes
Accepted

PSET2: CRACK vs POINTERS

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 ...
ChrisG's user avatar
  • 7,396
4 votes

C's DES based crypt function?

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. ...
ArtemPetrov's user avatar
4 votes
Accepted

pset2: Crack takes a lot of time

Answered by an instructor on reddit. here:https://www.reddit.com/r/cs50/comments/9o3eg8/pset2_crack_is_taking_a_lot_of_time/
Ali Amaim's user avatar
3 votes
Accepted

pset2 crack segmentation fault

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[...
Blauelf's user avatar
  • 21k
3 votes
Accepted

Easiest method to organize code

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 ...
ChrisG's user avatar
  • 7,396
3 votes
Accepted

pset2 crack - values are equal but the program claims equality is false

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 ...
Jason_V's user avatar
  • 182
3 votes
Accepted

CS50 crack confusion?

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....
ChrisG's user avatar
  • 7,396
2 votes
Accepted

Crypt() includes and compiling

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 ...
DinoCoderSaurus's user avatar
2 votes
Accepted

About the 'crack.c' part of the second hacker edition pset, what is really expected from us? (and a part about submitting)

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 ...
ChrisG's user avatar
  • 7,396
2 votes
Accepted

Trying to Increment Characters in a String

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 ...
Blauelf's user avatar
  • 21k
2 votes
Accepted

Passing string literal to a function: segmentation fault

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 ...
Steve Bunting's user avatar
2 votes
Accepted

Crack -- why does my code only work on the 4 character passwords?

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 ...
Vikrant Pradhan's user avatar
2 votes

I solved crack, but have a shallow understanding of the techniques used

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 ...
Vikrant Pradhan's user avatar
2 votes
Accepted

Use of crypt function - comparing output

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 ...
Blauelf's user avatar
  • 21k
2 votes

PSet 2: Crack - Faster Methods?

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 ...
user20049's user avatar
2 votes

pset2 crack segmentation fault

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. ...
Davis's user avatar
  • 144
2 votes
Accepted

pset2 Crack - Looping through fgets

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 ...
ChrisG's user avatar
  • 7,396
2 votes
Accepted

pset2 crack - conditional is not working

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 ...
Cliff B's user avatar
  • 69.2k
2 votes
Accepted

Crypt is not doing what I think it should do

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 ...
robert_x44's user avatar
2 votes
Accepted

pset2 crack - stelios only password I can't crack

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?
curiouskiwi's user avatar
  • 18.7k
2 votes

pset2 crack password does't work

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 ...
curiouskiwi's user avatar
  • 18.7k
2 votes
Accepted

How to better condense individual for loops per amount of characters on crack.c

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 ...
Blauelf's user avatar
  • 21k
2 votes
Accepted

PSet2 - Why does crack only work with four characters or less?

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', ...
curiouskiwi's user avatar
  • 18.7k
2 votes
Accepted

Pset2 can't crack stelios password

Did you let it run to completion or did you stop it while it was still running? This pset is notorious for running very long times for 5 letter passwords. Try running it overnight and see if it ...
Cliff B's user avatar
  • 69.2k
2 votes
Accepted

pset2/Crack - Terminal disconnected after some time of running

At pset3 recover/resize, they introduce the CS50 IDE at cs50.io, which I used. The lab has been unreliable for me, so I used that instead, pulling required files from https://github.com/cs50/labs/tree/...
Blauelf's user avatar
  • 21k
2 votes

Unable to get crypt to print correct hash

What's in alphabet? password3[2] = alphabet[k]; The salt is the first two digits of the hash, not the first 3. password3[2] needs to be set to the end of string marker, '\0'. If this answers your ...
Cliff B's user avatar
  • 69.2k
2 votes
Accepted

PSET6 CRACK (python)

Two things. First, and foremost, your program will keep going after it finds the password because your break only breaks out of the inner for loop. After finding the password, you should exit ...
curiouskiwi's user avatar
  • 18.7k
2 votes
Accepted

Week 2 CRACK: Erratic behavior with NULL '\0' when printing combinations of letters

This is a textbook example of "undefined behaviour". It gives different results on different machines because, well, there's a bug and there is no way to predict when or how it will "work" or fail. ...
DinoCoderSaurus's user avatar

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