0% found this document useful (0 votes)
2 views3 pages

Message

This C program generates a specified number of random Discord gift codes and checks their validity using the Discord API. It outputs valid codes to a file named 'Nitro_Codes.txt' and displays the results in the console. The program includes functions for screen clearing, slow typing effects, and handling CURL requests for API interactions.

Uploaded by

viganrexhepi224
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Message

This C program generates a specified number of random Discord gift codes and checks their validity using the Discord API. It outputs valid codes to a file named 'Nitro_Codes.txt' and displays the results in the console. The program includes functions for screen clearing, slow typing effects, and handling CURL requests for API interactions.

Uploaded by

viganrexhepi224
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <stdio.

h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <curl/curl.h>

#define LICENSE "Copyright (c) 2024 papaillsec\n"

#define CODE_LENGTH 16
#define MAX_CODES 100

void clearScreen() {
#ifdef _WIN32
system("cls");
#else
system("clear");
#endif
}

void slowType(const char *text, double speed) {


for (const char *ptr = text; *ptr != '\0'; ptr++) {
putchar(*ptr);
fflush(stdout);
struct timespec ts = {0, (long)(speed * 1e9)};
nanosleep(&ts, NULL);
}
putchar('\n');
}

void generateCode(char *code) {


const char charset[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (int i = 0; i < CODE_LENGTH; i++) {
code[i] = charset[rand() % (sizeof(charset) - 1)];
}
code[CODE_LENGTH] = '\0';
}

size_t writeCallback(void *contents, size_t size, size_t nmemb, void *userp) {


((char *)userp)[size * nmemb] = '\0';
strncat(userp, contents, size * nmemb);
return size * nmemb;
}

int checkCode(const char *code) {


CURL *curl;
CURLcode res;
char url[256];
char response[4096] = {0};

snprintf(url, sizeof(url), "https://discordapp.com/api/v9/entitlements/gift-


codes/%s?with_application=false&with_subscription_plan=true", code);

curl = curl_easy_init();
if (!curl) {
fprintf(stderr, "Error initializing CURL.\n");
return -1;
}
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, response);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L);

res = curl_easy_perform(curl);

if (res != CURLE_OK) {
fprintf(stderr, "CURL request failed: %s\n", curl_easy_strerror(res));
curl_easy_cleanup(curl);
return -1;
}

long httpCode = 0;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
curl_easy_cleanup(curl);

return httpCode == 200 ? 1 : 0;


}

int main() {
srand((unsigned int)time(NULL));

printf("%s", LICENSE);
sleep(3);
clearScreen();

slowType("Made by: papaillsec", 0.02);


sleep(1);
slowType("\nInput How Many Codes to Generate and Check: ", 0.02);

int num;
if (scanf("%d", &num) != 1 || num <= 0 || num > MAX_CODES) {
printf("Invalid input. Please enter a positive number up to %d.\n",
MAX_CODES);
return 1;
}

char codes[MAX_CODES][CODE_LENGTH + 1];

FILE *file = fopen("Nitro_Codes.txt", "w");


if (!file) {
perror("Error opening file");
return 1;
}

printf("\nGenerating %d codes:\n", num);

int validCount = 0;

for (int i = 0; i < num; i++) {


generateCode(codes[i]);
printf("Generated Code %d: %s\n", i + 1, codes[i]);

if (checkCode(codes[i])) {
fprintf(file, "Valid: https://discord.gift/%s\n", codes[i]);
printf("Valid Code: %s\n", codes[i]);
validCount++;
} else {
printf("Invalid Code: %s\n", codes[i]);
}
}

fclose(file);

printf("\nResults:\n");
printf("Valid: %d\n", validCount);
printf("Invalid: %d\n", num - validCount);
printf("Valid Codes saved in 'Nitro_Codes.txt'.\n");

printf("\nThe end! Press Enter 5 times to close the program.\n");


getchar(); // Consume leftover newline from previous input
for (int i = 0; i < 5; i++) {
getchar();
}

return 0;
}

You might also like