#include <stdio.h>
#include <stdlib.h>
#include <sys/sysinfo.h>

char* flag = "IGCTF{n0t_S0_r4nd0m}";

#define SEC_PER_MIN     (60)
#define SEC_PER_HOUR    (SEC_PER_MIN*60)
#define SEC_PER_DAY     (SEC_PER_HOUR*24)

void welcome() {
    printf("Welcome to Robbe's secure vault v2.\n");

    struct sysinfo info;
    sysinfo(&info);
    int uptime = info.uptime;
    int days = uptime / SEC_PER_DAY;
    uptime -= days * SEC_PER_DAY;
    int hours = uptime / SEC_PER_HOUR;
    uptime -= hours * SEC_PER_HOUR;
    int minutes = uptime / SEC_PER_MIN;
    uptime -= minutes * SEC_PER_MIN;
    int seconds = uptime;

    printf("I have been protecting Robbe's secrets for %i day(s), %i hours, %i minutes and %i seconds\n", days, hours, minutes, seconds);
}

int check_number(int number) {
    char buffer[32];
    int num;
    
    printf("> ");
    scanf("%32d", &num);

    if (num != rand() % 10) {
        printf("Incorrect, goodbye\n");
        exit(0);
    }
}

void login() {
    printf("Please enter the password to see all the secrets: \n");
    
    for (int i = 0; i < 20; i++) {
        check_number(i);
    }
}

void show_secrets()
{
    printf("+---------------------------------------------------+");
    printf("+ Netflix password:                        L0ve_m0m +");
    printf("+ Infogroep password:    R0bb3_1s_the_b3st_debugger +");
    printf("+ School password:              St4y_1n_school_k1ds +");
    printf("+ Random string:               %s +", flag);
    printf("+---------------------------------------------------+");
}

int main()
{
    setbuf(stdout, NULL);
    welcome();

    login();
    show_secrets();
}