#include <stdio.h>

const char secret[] = {0xC5, 0xC7, 0xCB, 0xBA, 0xC8, 0x93, 0xBA, 0xA6, 0xAD, 0xA0, 0xA3, 0xB5, 0x9F, 0x99, 0xC8, 0x9F, 0x9C, 0xBC, 0xA9, 0xA1, 0xA9, 0xA1, 0xAC, 0xA9, 0x9C, 0xA5, 0xA0, 0xA7, 0x91, 0x00};

int checkPswd(char buffer[]) {
    for (int i = 0; i < sizeof(secret) - 1; i++) {
        int* ii = &i;
        char* iii = (char*) ii;
        if (secret[i] != (((~(buffer[i])) + 15) ^ iii[3])) {
            return 1;
        }
    }
    return 0;
}

int pswdReadloop() {
    for (int i = 2; i >= 0; i--) {
        char buffer[1024];
        printf("> ");
        fflush(stdout);
        fgets(buffer, sizeof(buffer), stdin);
        if ((checkPswd(buffer)) == 0) {
            return 0;
        }
        printf("WRONG!!!! %d attempts remaining\n", i);
    }
    printf("How could you forget the password! Now all is lost because of you...\n");
    return 1;
}

int main() {
    printf("Give me the password!!!\n");
    int correct = pswdReadloop();
    if (correct == 0) {
        printf("Correct! Wonderful!\n");
    }
    return correct;
}
