Program compiles, but I just can't figure out how to go trough each string length generating process without segmentation fault. I could really use some pointers please!
#define _XOPEN_SOURCE
#include <unistd.h>
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
int main(int argc, string argv[])
{
if (argc !=2)
{
printf ("Hash needed!\n");
return 1;
}
string salt = "50";
string alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
string s = "word";
for (int i = 0; i <= 52; i++)
{
s[0] = alpha[i];
s[1] = '\0';
string oneLetter = crypt(s, salt);
int check = strcmp(argv[1], oneLetter);
if (check == 0)
{
printf("Password is %s", oneLetter);
return 0;
}
for (int j = 0; j <= 52; j++)
{
s[1] = alpha[j];
s[2] = '\0';
string twoLetters = crypt(s, salt);
int check2 = strcmp(argv[1], twoLetters);
if (check2 == 0)
{
printf("Password is %s", twoLetters);
return 0;
}
for (int k = 0; k <= 52; k++)
{
s[2] = alpha[k];
s[3] = '\0';
string threeLetters = crypt(s, salt);
int check3 = strcmp(argv[1], threeLetters);
if (check3 == 0)
{
printf("Password is %s", threeLetters);
return 0;
}
for (int l = 0; l <=52; l++)
{
s[3] = alpha[l];
s[4] = '\0';
string fourLetters = crypt(s, salt);
int check4 = strcmp(argv[1], fourLetters);
if (check4 == 0)
{
printf("Password is %s", fourLetters);
return 0;
}
}
}
}
}
}