Code:
char * salt_and_encrypted;
char *encrypted_passwords[] = {
"$6$KB$./CyqoGai/YYFHYBAT.tSdTuYEqW/XY2Y53D7xV/rU6QtJBThh1i3zffnptK6pJTUgMiZnV6fwjyyFMckLJuP.",
"$6$KB$sig9RP1foJmxO9Q/bzDukmLxWluzHxs5xGyNbQVdrFf.mc4jhztG6eV37qRKU/SHyuFvOh2H.bz8a3oEOkDLS.",
"$6$KB$5f63QAb4.5CLFgeTNRuRBQwLgyAxEefgjvIRqzhJqP9SGGTfCuP0ZuGhuxzivK6Z8Ywod4XaMIjXl8Sxi99iv1",
"$6$KB$CNwwbZPmnN53QUM0l19W9gkCsgUGWFPZntW9u94Oso4j0zHl6mQsPrNuOvFH4tSJiP4fo/MMq08lTeVXRtgGh1"
};
typedef struct arguments_t {
int start;
int stride;
char *salt_and_encrypted;
} arguments_t;
void *crack(void *be){
arguments_t *args = (arguments_t *) be;
printf("%c",'A');
int w, x, y, z; // Loop counters (added W for extra loop below)
char salt[8]; // String used in hashing the password. Need space for \0
char plain[8]; // The combination of letters currently being checked
char *enc; // Pointer to the encrypted password
int count = 0; // The number of combinations explored so far
substr(salt, salt_and_encrypted, 0, 7);
for(w=args->start; w<='Z'; w+=args->stride){
for(x='A'; x<='Z'; x++){
for(y='A'; y<='Z'; y++){
for(z=0; z<=99; z++){
sprintf(plain, "%c%c%c%02d", w, x, y, z);
enc = (char *) crypt(plain, salt);
count++;
if(strcmp(salt_and_encrypted, enc) == 0)
{
//printf("#%-8d%s %s\n", count, plain, enc);
}
else
{
//printf(" %-8d%s %s\n", count, plain, enc);
}
}
}
}
}
printf("%d solutions explored\n", count);
}
int main(int argc, char *argv[]){
//define 4 threads
pthread_t t1, t2, t3, t4;
//set argruments for each thread
arguments_t t1_args;
t1_args.salt_and_encrypted = encrypted_passwords;
t1_args.start = 0;
t1_args.stride = 4;
arguments_t t2_args;
t2_args.salt_and_encrypted = encrypted_passwords;
t2_args.start = 1;
t2_args.stride = 4;
arguments_t t3_args;
t3_args.salt_and_encrypted = encrypted_passwords;
t3_args.start = 2;
t3_args.stride = 4;
arguments_t t4_args;
t4_args.salt_and_encrypted = encrypted_passwords;
t4_args.start = 3;
t4_args.stride = 4;
void *crack();
//create each thread
pthread_create(&t1, NULL, crack, &t1_args);
pthread_create(&t2, NULL, crack, &t2_args);
pthread_create(&t3, NULL, crack, &t3_args);
pthread_create(&t4, NULL, crack, &t4_args);
//join the threads to end
pthread_join(t1, NULL);
pthread_join(t2, NULL);
pthread_join(t3, NULL);
pthread_join(t4, NULL);
}
Any help will be appreciated as the course material that was covered was not useful at all. If i have missed anything from the code that would make it easier for you to help me I will add later if needed.