Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int main() {
- srand(time(NULL));
- int isNumber = 0, isLowerCase = 0, isUpperCase = 0;
- char a, b, c, d, e, f, g, h;
- char captchaResult[9];
- for (int i = 1; i <= 8; i++) {
- int angka = rand() % 3 + 1;
- char random;
- if (angka == 1) {
- if (isNumber < 4) {
- random = '0' + rand() % 10;
- isNumber++;
- } else {
- i--;
- continue;
- }
- } else if (angka == 2) {
- if (isLowerCase < 2) {
- random = 'a' + rand() % 26;
- isLowerCase++;
- } else {
- i--;
- continue;
- }
- } else if (angka == 3) {
- if (isUpperCase < 2) {
- random = 'A' + rand() % 26;
- isUpperCase++;
- } else {
- i--;
- continue;
- }
- }
- if (i == 1) a = random;
- else if (i == 2) b = random;
- else if (i == 3) c = random;
- else if (i == 4) d = random;
- else if (i == 5) e = random;
- else if (i == 6) f = random;
- else if (i == 7) g = random;
- else if (i == 8) h = random;
- }
- sprintf(captchaResult, "%c%c%c%c%c%c%c%c", a, b, c, d, e, f, g, h);
- printf("CAPTCHA: %s\n", captchaResult);
- return 0;
- }
Add Comment
Please, Sign In to add comment