Quote:
Originally Posted by dila
The objective is to find valid 64-bit input keys that make the function return 'true'.
1. How many valid input keys are there?
|
A lot...
Code:
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <time.h>
bool check_key(uint64_t x) {
uint64_t r = x;
for (size_t i = 0; i < 64; ++i) {
for (size_t j = 0; j < 6; ++j) {
r ^= (((x >> (1 << j)) & (i >> j) & 1) << i);
}
}
return (x && r == 0);
}
uint64_t generate(void) {
uint64_t r, x;
do {
x = (((uint64_t)rand() * rand()) * rand()) ^ rand();
r = 0;
for (size_t i = 0; i < 64; ++i) {
for (size_t j = 0; j < 6; ++j) {
r ^= (((x >> (1 << j)) & (i >> j) & 1) << i);
}
}
} while (r == 0);
return r;
}
int main(int argc, char *argv[])
{
uint64_t r;
srand((unsigned)time(NULL));
r = generate();
if (check_key(r))
printf("%016llu => OK\n", r);
else
printf("%016llu => FAIL\n", r);
//_getch();
return 0;
}