#include <signal.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#include <string.h>

typedef char char_array[13];
const char psw[][13] = {
    "pMuzxQDIgCV9",
    "xCQzgmCBpqu2",
    "Dum+EEIenoCD",
    "MqO4VFBXthjf",
    "kiv+IpcxMFrY",
    "uTLfrYO4hRdX",
    "GBnbBQ8XjL10",
    "3dXLhhj74SUq",
    "PBfQujB0JwCk",
    "vFreTky8MrlW",
    "Smw6NADYrsTe",
    "5cDL1pbwkLA1",
    "i3GK7GP+1+pj",
    "cPgNAuWuMzW1",
    "TJWgPtgZkaW7",
    "SUsZXkg8dash",
    "xfs6xhXloQLP",
    "dk63xX3Wslbn",
    "BiR0yzElTLpV",
    "3SAoecG29oaW",
    "+Lk+7uiysfeX",
    "AfxPOnxqaWg+",
    "vWc9cEJYzMNj",
    "WxCQAWF1ypbj",
    "rFLxXmdCEtO1",
    "bPcTXLuhUCq6",
    "BfL3NiQzcPzC",
    "JFc2N+3Ok27w",
    "WQILiwG1Qyiw",
    "mssXMUL4OyXf",
    "oi7gTr2+TDbF",
    "NahPPldbqRk8",
    "1XOVgQI19Vam",
    "miYOZFsnXpM+",
    "ifN7ACCjGzjW",
    "iRJKqJejwGH+",
    "dCUYAVy5JJKf",
    "syOlpOJTlib2",
    "uweQVZIpLrK+",
    "rR20XegMEh2w",
    "lSXVAeNeBiq9",
    "eEwKPTvwZNf6",
    "0BdTkJWu4WT+",
    "HKA0ECJTbWln",
    "liyGJbj+ITtf",
    "+eP25hETqRrl",
    "WtA5SIepkbCO",
    "icfFukEtsWD8",
    "HcI6RJanuvOR",
    "b1y5L8mYAVsf",
    "tz4biM6Qrhe9",
    "4fg+oqIC4HIb",
    "nckMGQuqFmy6",
    "dIsiQQAPZGU3",
    "dNy8AdudJukV",
    "LYnXVcneueg7",
    "mtV8FCVEDhgw",
    "n13jYX70X6cP",
    "xCr0CQfuTMsO",
    "nudiMMUTLgV7",
    "WrRamXQ8UudS",
    "PMo4xkYuGyQK",
    "CYxHOhUqcnJ3",
    "oCmy07pF0+z5",
    "nPOTiwYfhxq8",
    "0VlM0kCqobH6",
    "Ddh5malRFZcm",
    "kRJBRdWxViz0",
    "Wa2eMx8YuFm6",
    "zOiuAuh+TefT",
    "K9P6h3qoLUFS",
    "MSBvMhPOodu3",
    "zM1OXPd0MB2u",
    "gkuyPlX8XXJK",
    "HdlZhKJ9OpAi",
    "En8xcW8EIfg7",
    "eZdPe0Sqo5P+",
    "pA+Ihqz5wo6v",
    "nvlmrNF3sgMT",
    "ZsemPae0eMgW",
    "wVgVJa7mRh71",
    "GQYaLJG1dDyZ",
    "C9lWfSX6J5Sk",
    "2lZ40pwtmCJJ",
    "KPBXBco4flJf",
    "yQF3pzfUftGl",
    "8bg+9NfvnsfW",
    "+WA8qISy5AuK",
    "rjERNfwmSSU5",
    "RaQ0otAuRJwO",
    "zE49Ln2AYtar",
    "CSj5J5ynf9tQ",
    "ITzYuBxgSIe4",
    "oneuxTg+xeeT",
    "CLfsAQ2RmB3+",
    "yTq9WfnRAmxa",
    "Mqd2iTnAKzmy",
    "HmG3eXvTBjVm",
    "YIoYAOIxwYA+",
    "0Kvr1Yt1nMeI",
};

bool hash(char* str){
    char* str1 = str;
    char* str2 = str;
    uint32_t foo = 0x56253667;

    do {
        str2 = str1 + 4;
        foo = foo ^ ((uint8_t)*str1 << 24 | (uint8_t)str1[1] << 16 | (uint8_t)str1[2] << 8 | (uint8_t)str1[3]);
        str1 = str2;
    } while (str + 12 != str2);
    return foo == 0x397a516d ? true : false;
}

const char list[] = {
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
    '/', '+'
};
char give_char(uint8_t index){
    if (index >= sizeof(list)) {
        printf("Error: Index out of bounds, max %zu\n", sizeof(list));
        exit(1);
    }
    return list[index];
}


int main(int argc, char *argv[]) {
    srand(time(NULL));

    // seed = 0x56253667;
    // answer = 0x3c3e386b;
    uint8_t mdw[4] = {0x6F, 0x5F, 0x67, 0x0a};
    // #define SOURCE_HASH 0x56 25 36 67
    // #define DESTINATION_HASH 0x39 7a 51 6d

    char password[13];
    const uint8_t max_char = sizeof(list);


    for(uint16_t n = 0; n < 100; n++) {
        for(uint8_t c = 0; c < 12; c++) {
            password[c] = psw[n][c];
        }
        password[12] = '\0';
        if (hash(password)) {
            printf("%s\n", password);
        } else {
            printf("Fuck: %s\n", password);
        }
    }
}
