#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char * alpha = "abcdefghijklmnopqrstuvwxyz";
char * bigAl = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char * digit = "0123456789";

int main (void)
{
    char y = 0;
    char syms[128] = {0};
    int found = 0;
    char passw[5] = { 0 };
    char guess[5] = { 0 };

    printf("Will you use characters (y/n): ");
    scanf(" %c", &y);
    if (y=='y') strcat(syms,alpha);

    printf("Will you use big characters (y/n): ");
    scanf(" %c", &y);
    if (y=='y') strcat(syms,bigAl);

    printf("Will you use numbers (y/n): ");
    scanf(" %c", &y);
    if (y=='y') strcat(syms,digit);

    if (strlen(syms))
    {
        printf("Enter your password: ");
        scanf("%4s", passw);
        for(char * c = syms; !found && *c; ++c)
        {
            guess[0] = *c;
            guess[1] = 0;
            if (strcmp(guess,passw) == 0)
            {
                found = 1; break;
            }
            for(char * c1 = syms; !found && *c1; ++c1)
            {
                guess[1] = *c1;
                guess[2] = 0;
                if (strcmp(guess,passw) == 0)
                {
                    found = 1; break;
                }
                for(char * c2 = syms; !found && *c2; ++c2)
                {
                    guess[2] = *c2;
                    guess[3] = 0;
                    if (strcmp(guess,passw) == 0)
                    {
                        found = 1; break;
                    }
                    for(char * c3 = syms; !found && *c3; ++c3)
                    {
                        guess[3] = *c3;
                        if (strcmp(guess,passw) == 0)
                        {
                            found = 1; break;
                        }
                    }
                }
            }
        }
    }
    printf("Password = [%s]\n",(found) ? guess : "NOT FOUND");
    printf("done.\n");

    return EXIT_SUCCESS;
}

