fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char * alpha = "abcdefghijklmnopqrstuvwxyz";
  6. char * bigAl = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  7. char * digit = "0123456789";
  8.  
  9. int main (void)
  10. {
  11. char y = 0;
  12. char syms[128] = {0};
  13. int found = 0;
  14. char passw[5] = { 0 };
  15. char guess[5] = { 0 };
  16.  
  17. printf("Will you use characters (y/n): ");
  18. scanf(" %c", &y);
  19. if (y=='y') strcat(syms,alpha);
  20.  
  21. printf("Will you use big characters (y/n): ");
  22. scanf(" %c", &y);
  23. if (y=='y') strcat(syms,bigAl);
  24.  
  25. printf("Will you use numbers (y/n): ");
  26. scanf(" %c", &y);
  27. if (y=='y') strcat(syms,digit);
  28.  
  29. if (strlen(syms))
  30. {
  31. printf("Enter your password: ");
  32. scanf("%4s", passw);
  33. for(char * c = syms; !found && *c; ++c)
  34. {
  35. guess[0] = *c;
  36. guess[1] = 0;
  37. if (strcmp(guess,passw) == 0)
  38. {
  39. found = 1; break;
  40. }
  41. for(char * c1 = syms; !found && *c1; ++c1)
  42. {
  43. guess[1] = *c1;
  44. guess[2] = 0;
  45. if (strcmp(guess,passw) == 0)
  46. {
  47. found = 1; break;
  48. }
  49. for(char * c2 = syms; !found && *c2; ++c2)
  50. {
  51. guess[2] = *c2;
  52. guess[3] = 0;
  53. if (strcmp(guess,passw) == 0)
  54. {
  55. found = 1; break;
  56. }
  57. for(char * c3 = syms; !found && *c3; ++c3)
  58. {
  59. guess[3] = *c3;
  60. if (strcmp(guess,passw) == 0)
  61. {
  62. found = 1; break;
  63. }
  64. }
  65. }
  66. }
  67. }
  68. }
  69. printf("Password = [%s]\n",(found) ? guess : "NOT FOUND");
  70. printf("done.\n");
  71.  
  72. return EXIT_SUCCESS;
  73. }
  74.  
  75.  
Success #stdin #stdout 0s 2172KB
stdin
y
y
n
aZZZ
stdout
Will you use characters (y/n): Will you use big characters (y/n): Will you use numbers (y/n): Enter your password: Password = [aZZZ]
done.