Hot answers tagged

4

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


2

Crack is a 'more comfortable' problem, so it assumes that you have programming experience and that you have a knowledge of arrays, strings, loops, etc. If you don't consider yourself in the 'more comfortable' group of students, then you will find this to be a challenging problem requiring lots of outside study (you cannot solve this with the materials ...


1

Your code doesn't wrong actually but your assuming that passwords have four characters only because of this wrong assumption some of hashes doesn't return anything. for example try this hash: 50YHuxoCN9Jkc with this modification it returns two character Password which is 'JH' ( this is your code, i just modified to check two characters only as you can see ) ...


1

The problem is that you have essentially created an infinite loop. Initially when your while code starts, your first for loop runs, then your second, then third and then fourth but they never check the while loop condition, so they keep on going on till the letters in key are "zzzz" and if the password you gave is not "zzzz" the while loop condition (which ...


1

The 'more comfortable' problems seem to be geared toward people who have at least a little prior experience in programming. The entire problem can be solved with arrays and loops (in under 100 lines of code), so you don't need anything specific from subsequent lectures. As you complete more lectures and problem sets, you'll gain some of that experience and ...


1

It looks like strcmp() isn't being used as it should. ( I don't understand why the result of strcmp is being checked for > 1. ) The strcmp(s1, s2) function compares two strings, char by char and returns one of 3 possible results. If the strings are identical, it will return 0. If the first unmatched char in s1 is smaller than the char compared in s2, then ...


1

In C, strings are arrays of char. You assign a string to a char variable, maybe you meant '\0' (string terminator) instead of "" (empty string). You cannot add them to concatenate, you'd have to build your own string, like for example char test[5]; test[0] = d; test[1] = c; test[2] = b; test[3] = a; test[4] = '\0'; Last character is the null terminator, ...


1

Yes, you can have password that are mixed case. I believe you already know how to join strings or individual chars together, for example from exercises where we learn to printf "Hello" + name together. Can you use something like that to join together different chars? For the question about generating both lower and uppercase letters: have you considered ...


1

The salt must be saved together with the hash, so that we can reproduce the result. A password check function would hash a password using the same salt and compare the results. The salt here are the first two characters of the hash. Correct, though I would not say "encrypt" here. The password is not the thing that's encrypted, but the source of the key to ...


1

I'd remove the space from the pool of valid password characters, and try again. Maybe you saw a less than 5 character password with some space character in front. You don't have a break; after done = true;, which means the password is shortened by one character. Also, it's pretty pointless to allocate memory for both temp and out, but then assign one to the ...


1

The UndefinedBehaviorSanitizer (aka UBSan) relates to execution-time bugs caused by various kinds of undefined programme behaviour. For instance, Using misaligned or null pointer, Signed integer overflow, or Conversion to, from, or between floating-point types which would overflow the destination. The odds are the line 65 seating characters[c4] access an ...


1

Keep in mind that a "string" in C is simply a character array that is null terminated. As such, your salt variable is not a string, nor is your temp variable in all cases. As a consequence, when you call crypt, which is expecting 2 strings, it will look at the location of each string and keep reading until it finds the null char that signifies the end. If ...


1

This program takes a notoriously long time to run. It's also an exercise in making code more efficient. Also, at this point, you should start being able to answer questions on your own, like this one: Is there something wrong with [my code]? Good question. Did you run tests and get valid and correct answers? Did you encode simple passwords on your own ...


1

What you're really trying to say is that it compiles, but it doesn't work. There's a major problem with the logic. I won't spoil it for you, but I'll point you at it. Add a print statement to print out all of the single char keys and another to print out all of the two char keys inside their respective loops. I would also add that the code above doesn't ...


1

Unfortunately, there was a typo in the spec. The first example given was correct: ./crack 50fkUxYHbnXGw rofl but when repeated later in the spec, it showed ROFL in error. This has been corrected. Thanks for the report.


1

The spec is perfectly correct. More than likely, you don't have #define _XOPEN_SOURCE #include <unistd.h> At the very top of your program (ie, before any other #includes). If you move that to the top even above the other includes in your header, it will compile fine.


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