Your task is to reverse engineer the provided C code and uncover the correct key to unlock the flag. (Capitalization counts here!)
#include <stdio.h>
#include <string.h>
#include <curl/curl.h>
void generate_key(char *key) {
int i;
int base_values[] = {96, 101, 118, 120, 127};
for (i = 0; i < 5; i++) {
base_values[i] = base_values[i] + 3;
base_values[i] = base_values[i] * 2;
base_values[i] = base_values[i] / 2;
base_values[i] = base_values[i] - (i * 2);
base_values[i] = base_values[i] - 1;
}
for (i = 0; i < 5; i++) {
key[i] = (char)base_values[i];
}
key[5] = '\0';
}
int validate_key(char *key) {
CURL *curl;
CURLcode res;
int is_valid = 0;
curl = curl_easy_init();
if(curl) {
char post_data[50];
sprintf(post_data, "key=%s", key);
curl_easy_setopt(curl, CURLOPT_URL, "https://fake-server.com/validate");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_data);
res = curl_easy_perform(curl);
if(res == CURLE_OK) {
printf("Server validation succeeded!\n");
is_valid = 1;
} else {
printf("Server validation failed: %s\n", curl_easy_strerror(res));
}
curl_easy_cleanup(curl);
}
return is_valid;
}
int main() {
char input[100];
char correct_key[6];
generate_key(correct_key);
printf("Enter the secret key: ");
scanf("%s", input);
if (strcmp(input, correct_key) == 0) {
if (validate_key(correct_key)) {
printf("Correct! The flag will be sent by the server.\n");
} else {
printf("Server validation failed.\n");
}
} else {
printf("Incorrect key. Try again.\n");
}
return 0;
}