Skip to content

Instantly share code, notes, and snippets.

Created January 20, 2018 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/d69a7b826f8a1b2330aef173fb121ba3 to your computer and use it in GitHub Desktop.
Save anonymous/d69a7b826f8a1b2330aef173fb121ba3 to your computer and use it in GitHub Desktop.
SteamKeyGen
void generateKey (char* s, char type, char* chars) {
switch (type) {
case '1': {
for (short i = 0; i < 17; i++)
s[i] = chars[rand() % 36];
s[5] = s[11] = '-';
s[17] = '\0';
break;
}
case '2': {
for (short i = 0; i < 29; i++)
s[i] = chars[rand() % 36];
s[5] = s[11] = s[17] = s[23] = '-';
s[29] = '\0';
break;
}
case '3': {
s[0] = chars[rand() % 10];
s[1] = chars[rand() % 10];
s[2] = chars[rand() % 10];
for (short i = 3; i < 15; i++)
s[i] = chars[rand() % 36];
s[15] = ' ';
s[16] = chars[rand() % 10];
s[17] = chars[rand() % 10];
s[18] = '\0';
break;
}
}
}
void clearBuffer () {
while (getchar() != '\n');
}
char safeTypeInput (char type) {
while (type < '1' || type > '3') {
printf("Type of a key: ");
scanf("%c", &type);
clearBuffer();
}
return type;
}
int safeNumberInput (char* number) {
while (1) {
printf("Number of keys: ");
scanf("%s", number);
for (short i = 0; number[i] != '\0'; i++) {
if (!isdigit(number[i])) {
clearBuffer();
safeNumberInput(number);
}
return atoi(number);
}
}
#include "stdlib.h"
#include "stdio.h"
#include "ctype.h"
#include "time.h"
#include "functions.h"
char chars[36] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main() {
srand(time(NULL));
char typeOfKeys = '0';
char numberOfKeysString[21];
int numberOfKeys;
char stringForKey[29];
printf("SteamKeyGen\n\n1. AAAAA-BBBBB-CCCCC\n2. AAAAA-BBBBB-CCCCC-DDDDD-EEEEE\n3. 237ABCDGHJLPRST 23\n\n");
typeOfKeys = safeTypeInput(typeOfKeys);
numberOfKeys = safeNumberInput(numberOfKeysString);
FILE *f = fopen("Keys.txt", "w");
while (numberOfKeys) {
generateKey(stringForKey, typeOfKeys, chars);
fprintf(f, "%s\n", stringForKey);
numberOfKeys--;
}
fclose(f);
printf("\nFinished!");
clearBuffer();
getchar();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment