Hot answers tagged

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, ...
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 ...
user avatar
  • 7,326
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 ...
user avatar
4 votes
Accepted

string comparison & crack.c

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 ...
user avatar
  • 7,326
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. ...
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/
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[...
user avatar
  • 20.7k
3 votes
Accepted

Hacker2, Crack: Optimisations

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 ...
user avatar
  • 17.3k
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....
user avatar
  • 7,326
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 ...
user avatar
  • 184
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 ...
user avatar
  • 7,326
2 votes
Accepted

Reading a line from a file

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. ...
user avatar
  • 1,359
2 votes
Accepted

What's the purpose of the 'salt' string? Isn't it contained in the hashed string anyway?

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 ...
user avatar
  • 17.3k
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 ...
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 ...
user avatar
  • 7,326
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 ...
user avatar
  • 20.7k
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 ...
user avatar
  • 7,326
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 ...
user avatar
  • 63.2k
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. ...
user avatar
  • 144
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 ...
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 ...
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 ...
user avatar
  • 20.7k
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 ...
user avatar
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 ...
user avatar
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 ...
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?
user avatar
  • 18.3k
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 ...
user avatar
  • 18.3k
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 ...
user avatar
  • 20.7k
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', ...
user avatar
  • 18.3k

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