Skip to content

Instantly share code, notes, and snippets.

@Menci
Created February 3, 2021 13:58
Show Gist options
  • Save Menci/8ff5048daf0eb4d23e0b8bf9a46b8ef1 to your computer and use it in GitHub Desktop.
Save Menci/8ff5048daf0eb4d23e0b8bf9a46b8ef1 to your computer and use it in GitHub Desktop.
The algorithm of Arcaea's lowest.world/connect
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <openssl/md5.h>
int main() {
time_t time_val = time(NULL);
struct tm *t = gmtime(&time_val);
size_t year = t->tm_year + 1900;
size_t month = t->tm_mon;
size_t day = t->tm_mday;
char s[100];
size_t l = sprintf(s, "%zuori%zuwol%zuoihs%zuotas", year, month, day, day);
printf("s = %s\n", s);
char digest[16];
MD5(s, l, digest);
char digest_string[32 + 1];
for (size_t i = 0; i < 16; i++) {
sprintf(&digest_string[i * 2], "%2.2hhx", digest[i]);
}
digest_string[32] = 0;
printf("md5 = %s\n", digest_string);
const char *table = "qwertyuiopasdfghjklzxcvbnm1234567890";
const size_t tl = strlen(table);
char transformed[32 + 1];
for (size_t i = 0; i < 32; i++)
transformed[i] = table[digest_string[i] % tl];
transformed[32] = 0;
printf("transformed = %s\n", transformed);
const size_t pos[] = { 1, 20, 4, 30, 2, 11, 23 };
const size_t pos_count = sizeof(pos) / sizeof(pos[0]);
char code[10], *p = code;
for (size_t i = 0; i < pos_count; i++) {
size_t j = pos[i];
*p++ = transformed[j];
}
*p = 0;
printf("code = %s\n", code);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment