#include
#include
#include
#include
#include
#define BUFFER_SIZE 64
// KEY: [0-9]{4}-[0-9]{4}-[0-9A-Z]{6}
#define KEY “1234-4321-123456”
/**
/**
(virtual address found) + (offset of .text section) - (virtual address of .text section) - (image base) = (file offset).
Using Address Converter in CFF Explorer is recommended),
static uint_fast8_t getDigit(uint_fast32_t number, uint_fast8_t digit){
return (uint_fast8_t) ((number / (uint_fast32_t)pow(10, digit - 1)) % 10);
}
// inverse of privHash: nextHash(privHash(x, y, c), c, y, c) == x
static uint_fast32_t nextHash(uint_fast32_t hash, uint_fast8_t byte, uint_fast32_t magic) {
for (uint_fast8_t bitIndex = 0; bitIndex <= 7; bitIndex++) {
uint_fast8_t bit = (byte >> bitIndex) & 1;
if (bit + ((hash - bit) & ~1) == hash) {
hash = (hash - bit) >> 1;
} else {
hash = ((magic - bit) ^ hash) >> 1;
}
}
return hash;
}
/*
static uint_fast32_t privHash(uint_fast32_t hash, uint_fast8_t byte, uint_fast32_t magic) {
for (uint_fast8_t bitIndex = 7; bitIndex >= 0; bitIndex–) {
uint_fast8_t bit = (byte >> bitIndex) & 1;
uint_fast32_t temp = (hash << 1) + bit;
if (hash & 0x8000) {
temp ^= magic;
}
hash = temp;
}
return hash;
}
*/
void genPass(char* string, uint_fast8_t length) {
uint_fast32_t hash = INIT_HASH;
for (int byteIndex = length - 1; byteIndex >= 0; byteIndex--) {
hash = nextHash(hash, string[byteIndex], HASH_MAGIC_1);
}
uint_fast32_t n1 = 0;
while (nextHash(nextHash(hash, n1 & 0xFF, HASH_MAGIC_1), n1 >> 8, HASH_MAGIC_1) != GOOD_HASH) {
if (++n1 >= 0xFFFF) {
printf("Failed to find a key!");
return;
}
}
n1 = (uint_fast32_t) floor(((n1 + 0x72FA) & 0xFFFF) * 99999.0 / 0xFFFF);
uint_fast32_t temp = (n1/1000*1000) + n1%1000/100 + n1%100*10;
temp = (uint_fast32_t) ceil((temp / 99999.0) * 0xFFFF);
temp = nextHash(nextHash(0, temp & 0xFF, HASH_MAGIC_2), temp >> 8, HASH_MAGIC_2);
for (int byteIndex = length - 1; byteIndex >= 0; byteIndex--) {
temp = nextHash(temp, (uint_fast8_t) string[byteIndex], HASH_MAGIC_2);
}
uint_fast16_t n2 = 0;
while (nextHash(nextHash(temp, n2 & 0xFF, HASH_MAGIC_2), n2 >> 8, HASH_MAGIC_2) != GOOD_HASH) {
if (++n2 >= 0xFFFF) {
printf("Failed to find a key!");
return;
}
}
n2 = (uint_fast16_t) floor((n2 & 0xFFFF) * 99999.0 / 0xFFFF);
printf("%u%u%u%u-%u%u%u-%u%u%u::1",
getDigit(n2,2),getDigit(n1,2),getDigit(n1,4),getDigit(n1,5),
getDigit(n2,1),getDigit(n1,3),getDigit(n2,5),
getDigit(n2,3),getDigit(n1,1),getDigit(n2,4)
);
}
int main(){
char buffer[BUFFER_SIZE];
int offset = 0;
scanf("%s%n", buffer, &offset); // Input MathID here
strcpy(buffer+offset, “$” LICENSE_TYPE “&” KEY);
genPass(buffer, (uint_fast8_t) strlen(buffer));
return 0;
}