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>
#define _XOPEN_SOURCE
#include <unistd.h>
#include <crypt.h>
int main(int argc , string argv[]){
if (argc != 2){ //checks for valid commend line input
printf("Invalid");
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';
break;
}
if (pass[digit] >= 'A' && pass[digit] <'z'){
pass[digit]++;
break;
}
if (pass[digit] == 'z') {
pass[digit] = 'A';
digit++;
}
if (digit >= passSize){ // checks if all combos hav bin done
printf("no PassWord found\n");
return 0;
break;
}
}
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;
break;
//printf("%s\n", crypt(pass, "50"));
}printf("%s\n", cryptPass);
printf("%s\n", hashPass);
}
}
}
any help / insight appreciated!