i'm brand new here also bit dyslexic my spelling can be rough in comments so bee gentle pls:)

basically I've made a code for crack.c which cracks 1-4digit passwords but does not work with 5 digit passwords i think I've declared the array correctly to have space for the null ect.

when running though in debug mode starting it at char pass[6] = { 'A' , 'A' , 'A' , 'A' , 'A' , '\0' }; // too make sure i don't need 2 go thought all the 1-4digit passwords

the hash I'm looking for CAAAA when hashed is different than when i hash it using crypt with the same salt of course. (i checked with the output hash from crack.c and did it find CAAAA)

I also checked if the hash matched AAAA or CAAA incase it was chopping off a letter cause of some part of C i don't understand yet.

another side note atm my code is way away from being optimised that was what i was planning to work on next and wanna try figure out for myself:)

anyway heres the code in question:

#include <stdio.h>
#include <cs50.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
#include <crypt.h>

int main(int argc , string argv[]){

if (argc != 2){     //checks for valid commend line input
    return 1;
} else {

int passSize = 6; // sets password max length to check
char pass[6] = { 0 , 0 , 0 , 0 , 0 , 0 };//makes array 4 brute 

string cryptPass;
int digit = 0;
string hashPass = argv[1];

char salt[3];

strncpy(salt, hashPass, 2);  //copys first to digits of hashed password salt

printf("%s\n", salt);

while (passSize >= digit){  //loop to go over every combo of alphabet 

 digit = 0;
while (digit < passSize){

    if (pass[digit] == 0){
    pass[digit] = 'A';

        if (pass[digit] >= 'A' && pass[digit] <'z'){

            if (pass[digit] == 'z') {
            pass[digit] = 'A';

                if (digit >= passSize){ // checks if all combos hav bin done

                    printf("no PassWord found\n");
                    return 0;

printf("password: '%s'\n", pass); // used for debugging
//printf("password: '%s'\n", salt);
cryptPass = crypt(pass, salt); //creates a variable with a hashed try
if (strcmp(hashPass , cryptPass) == 0) { //compares hashed try too hash
printf("password Found: %s\n" , pass); // if they are match returns pword

return 0;
//printf("%s\n", crypt(pass, "50"));
}printf("%s\n", cryptPass);
printf("%s\n", hashPass);


any help / insight appreciated!


First, please fix your indentation. It's hard to see what belongs to which code block.

Is int passSize = 6 intentional? Shouldn't it be 5?

Your code never sets salt[2] to '\0'. But I guess crypt won't look at the third character anyway, as the salt is two characters by definition. Your printf does care. Maybe you're lucky and the next byte is zero by coincidence.

Note that pass[digit] >= 'A' && pass[digit] <'z' includes 6 characters that are not alphabetic. Might make your code slightly less efficient.

  • okay ill try work on the indentation still all very new 2 me. the printf for salt has been coming up with 50 and no more so i guess i was lucky but ill assign the last digit a null anyway. im aware of the efficiency issues but would rather have a working code before making an array of characters to illiterate over or w/e it turns out ill need to do – aoc Jun 5 '18 at 17:57
  • For the indentation, style50 will yell at you, try to follow its advice, most times it's right. And I've modified your code to use passSize of 5, and it solved most of the sample hashes so far, just 50GApilQSG3E2 seems to resist, might be one of the 5 character passwords which take a lot longer. – Blauelf Jun 5 '18 at 18:12
  • oh thats weird originally i had it set with 5 but changed it 2 6 cause 4 worked with 5 so i was just trying random stuff out. i forgot about style50 lol i was reading on the rules of indenting ill use style50 now. have any 5 digit passes hashed? im going to change it back and see if i can get it fixed. thanks alot for the help – aoc Jun 5 '18 at 19:40
  • the one your having issue with running is a 5digit code indeed and it took me 3days to run it for some reason (with printf statements guessin that slows it down abit) its the only one i tried as it took so long hence me hashing my own CAAAA to crack as it takes much shorter time. ive finished styling it style50 returns looks good! so i can repost it if that would make it eazyer – aoc Jun 5 '18 at 20:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .