Xractz

CAPTCHA GENERATOR USING C

May 11th, 2024
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | Source Code | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int main() {
  6.   srand(time(NULL));
  7.   int isNumber = 0, isLowerCase = 0, isUpperCase = 0;
  8.   char a, b, c, d, e, f, g, h;
  9.   char captchaResult[9];
  10.  
  11.   for (int i = 1; i <= 8; i++) {
  12.     int angka = rand() % 3 + 1;
  13.     char random;
  14.  
  15.     if (angka == 1) {
  16.       if (isNumber < 4) {
  17.         random = '0' + rand() % 10;
  18.         isNumber++;
  19.       } else {
  20.         i--;
  21.         continue;
  22.       }
  23.     } else if (angka == 2) {
  24.       if (isLowerCase < 2) {
  25.         random = 'a' + rand() % 26;
  26.         isLowerCase++;
  27.       } else {
  28.         i--;
  29.         continue;
  30.       }
  31.     } else if (angka == 3) {
  32.       if (isUpperCase < 2) {
  33.         random = 'A' + rand() % 26;
  34.         isUpperCase++;
  35.       } else {
  36.         i--;
  37.         continue;
  38.       }
  39.     }
  40.  
  41.     if (i == 1) a = random;
  42.     else if (i == 2) b = random;
  43.     else if (i == 3) c = random;
  44.     else if (i == 4) d = random;
  45.     else if (i == 5) e = random;
  46.     else if (i == 6) f = random;
  47.     else if (i == 7) g = random;
  48.     else if (i == 8) h = random;
  49.   }
  50.  
  51.   sprintf(captchaResult, "%c%c%c%c%c%c%c%c", a, b, c, d, e, f, g, h);
  52.   printf("CAPTCHA: %s\n", captchaResult);
  53.  
  54.   return 0;
  55. }
Add Comment
Please, Sign In to add comment