rakovskij-stanislav.github.io

Назад

Give me key for this crackme:
#include <stdlib.h>
#include <string.h>
#include <stdio.h> 

struct transition {
    int symb;
    struct state *next;
};


struct state{
    int value;
    struct transition *transitions;
};

struct state *init_state;
struct state error_state;

struct transition * create_trans(struct transition *new, char symb, struct state *state){
    new->symb = symb;
    new->next = state;
}

void init_states(){
    struct state **a = malloc(sizeof(struct state *) * 49);
for(int i=0; i < 49 ; ++i){
    a[i] = malloc(sizeof(struct state));
    a[i]->transitions = NULL;
};
struct transition *tptr;
int b = 0;
b += 0;
a[b]->value = 76515;
tptr = malloc(sizeof(struct transition)*3);
a[b]->transitions = tptr;
create_trans(tptr, 'R', a[b + 1]);++tptr;
create_trans(tptr, 'F', a[b + 11]);++tptr;
tptr->symb = -1;
b = 0;
b += 1;
a[b]->value = 188963;
tptr = malloc(sizeof(struct transition)*2);
a[b]->transitions = tptr;
create_trans(tptr, 'Y', a[b + 1]);++tptr;
tptr->symb = -1;
b = 1;
b += 1;
a[b]->value = 763877;
tptr = malloc(sizeof(struct transition)*2);
a[b]->transitions = tptr;
create_trans(tptr, 'Y', a[b + 1]);++tptr;
tptr->symb = -1;
b = 2;
b += 1;
a[b]->value = 166553;
tptr = malloc(sizeof(struct transition)*2);
a[b]->transitions = tptr;
create_trans(tptr, 'D', a[b + 1]);++tptr;
tptr->symb = -1;
b = 3;
b += 1;
a[b]->value = 438321;
tptr = malloc(sizeof(struct transition)*3);
a[b]->transitions = tptr;
create_trans(tptr, 'A', a[b + 1]);++tptr;
create_trans(tptr, 'n', a[b + 4]);++tptr;
tptr->symb = -1;
b = 4;
b += 1;
a[b]->value = 168617;
tptr = malloc(sizeof(struct transition)*3);
a[b]->transitions = tptr;
create_trans(tptr, 'l', a[b + 2]);++tptr;
create_trans(tptr, 'n', a[b + 1]);++tptr;
tptr->symb = -1;
b = 5;
b += 2;
a[b]->value = 488992;
tptr = malloc(sizeof(struct transition)*1);
a[b]->transitions = tptr;
tptr->symb = -1;
b = 5;
b += 1;
a[b]->value = 480599;
tptr = malloc(sizeof(struct transition)*1);
a[b]->transitions = tptr;
tptr->symb = -1;
b = 4;
b += 4;
a[b]->value = 731519;
tptr = malloc(sizeof(struct transition)*3);
a[b]->transitions = tptr;
create_trans(tptr, 'w', a[b + 1]);++tptr;
create_trans(tptr, 'v', a[b + 2]);++tptr;
tptr->symb = -1;
b = 8;
b += 1;
a[b]->value = 609514;
tptr = malloc(sizeof(struct transition)*1);
a[b]->transitions = tptr;
tptr->symb = -1;
b = 8;
b += 2;
a[b]->value = 830951;
tptr = malloc(sizeof(struct transition)*1);
a[b]->transitions = tptr;
tptr->symb = -1;
b = 0;
b += 11;
a[b]->value = 586935;
tptr = malloc(sizeof(struct transition)*3);
a[b]->transitions = tptr;
create_trans(tptr, 'X', a[b + 21]);++tptr;
create_trans(tptr, 'e', a[b + 1]);++tptr;
tptr->symb = -1;
b = 11;
b += 21;
a[b]->value = 266243;
tptr = malloc(sizeof(struct transition)*3);
a[b]->transitions = tptr;
create_trans(tptr, 'p', a[b + 11]);++tptr;
create_trans(tptr, 'K', a[b + 1]);++tptr;
tptr->symb = -1;
b = 32;
b += 11;
a[b]->value = 568276;
tptr = malloc(sizeof(struct transition)*2);
a[b]->transitions = tptr;
create_trans(tptr, 'T', a[b + 1]);++tptr;
tptr->symb = -1;
b = 43;
b += 1;
a[b]->value = 690425;
tptr = malloc(sizeof(struct transition)*3);
a[b]->transitions = tptr;
create_trans(tptr, 'h', a[b + 1]);++tptr;
create_trans(tptr, 'w', a[b + 3]);++tptr;
tptr->symb = -1;
b = 44;
b += 1;
a[b]->value = 487985;
tptr = malloc(sizeof(struct transition)*2);
a[b]->transitions = tptr;
create_trans(tptr, 's', a[b + 1]);++tptr;
tptr->symb = -1;
b = 45;
b += 1;
a[b]->value = 43938;
tptr = malloc(sizeof(struct transition)*1);
a[b]->transitions = tptr;
tptr->symb = -1;
b = 44;
b += 3;
a[b]->value = 281174;
tptr = malloc(sizeof(struct transition)*2);
a[b]->transitions = tptr;
create_trans(tptr, 'V', a[b + 1]);++tptr;
tptr->symb = -1;
b = 47;
b += 1;
a[b]->value = 109931;
tptr = malloc(sizeof(struct transition)*1);
a[b]->transitions = tptr;
tptr->symb = -1;
b = 32;
b += 1;
a[b]->value = 488088;
tptr = malloc(sizeof(struct transition)*3);
a[b]->transitions = tptr;
create_trans(tptr, 'y', a[b + 1]);++tptr;
create_trans(tptr, 'G', a[b + 4]);++tptr;
tptr->symb = -1;
b = 33;
b += 1;
a[b]->value = 268276;
tptr = malloc(sizeof(struct transition)*2);
a[b]->transitions = tptr;
create_trans(tptr, 'z', a[b + 1]);++tptr;
tptr->symb = -1;
b = 34;
b += 1;
a[b]->value = 171788;
tptr = malloc(sizeof(struct transition)*2);
a[b]->transitions = tptr;
create_trans(tptr, 'z', a[b + 1]);++tptr;
tptr->symb = -1;
b = 35;
b += 1;
a[b]->value = 22394;
tptr = malloc(sizeof(struct transition)*1);
a[b]->transitions = tptr;
tptr->symb = -1;
b = 33;
b += 4;
a[b]->value = 232479;
tptr = malloc(sizeof(struct transition)*3);
a[b]->transitions = tptr;
create_trans(tptr, 'q', a[b + 1]);++tptr;
create_trans(tptr, 'c', a[b + 3]);++tptr;
tptr->symb = -1;
b = 37;
b += 1;
a[b]->value = 479579;
tptr = malloc(sizeof(struct transition)*2);
a[b]->transitions = tptr;
create_trans(tptr, 'i', a[b + 1]);++tptr;
tptr->symb = -1;
b = 38;
b += 1;
a[b]->value = 358847;
tptr = malloc(sizeof(struct transition)*1);
a[b]->transitions = tptr;
tptr->symb = -1;
b = 37;
b += 3;
a[b]->value = 794087;
tptr = malloc(sizeof(struct transition)*3);
a[b]->transitions = tptr;
create_trans(tptr, 'm', a[b + 2]);++tptr;
create_trans(tptr, 'w', a[b + 1]);++tptr;
tptr->symb = -1;
b = 40;
b += 2;
a[b]->value = 389350;
tptr = malloc(sizeof(struct transition)*1);
a[b]->transitions = tptr;
tptr->symb = -1;
b = 40;
b += 1;
a[b]->value = 493408;
tptr = malloc(sizeof(struct transition)*1);
a[b]->transitions = tptr;
tptr->symb = -1;
b = 11;
b += 1;
a[b]->value = 66397;
tptr = malloc(sizeof(struct transition)*3);
a[b]->transitions = tptr;
create_trans(tptr, 'q', a[b + 12]);++tptr;
create_trans(tptr, 'N', a[b + 1]);++tptr;
tptr->symb = -1;
b = 12;
b += 12;
a[b]->value = 253611;
tptr = malloc(sizeof(struct transition)*3);
a[b]->transitions = tptr;
create_trans(tptr, 'R', a[b + 4]);++tptr;
create_trans(tptr, 'n', a[b + 1]);++tptr;
tptr->symb = -1;
b = 24;
b += 4;
a[b]->value = 530633;
tptr = malloc(sizeof(struct transition)*2);
a[b]->transitions = tptr;
create_trans(tptr, 'h', a[b + 1]);++tptr;
tptr->symb = -1;
b = 28;
b += 1;
a[b]->value = 482691;
tptr = malloc(sizeof(struct transition)*3);
a[b]->transitions = tptr;
create_trans(tptr, 'G', a[b + 2]);++tptr;
create_trans(tptr, 'f', a[b + 1]);++tptr;
tptr->symb = -1;
b = 29;
b += 2;
a[b]->value = 390112;
tptr = malloc(sizeof(struct transition)*1);
a[b]->transitions = tptr;
tptr->symb = -1;
b = 29;
b += 1;
a[b]->value = 594976;
tptr = malloc(sizeof(struct transition)*1);
a[b]->transitions = tptr;
tptr->symb = -1;
b = 24;
b += 1;
a[b]->value = 15927;
tptr = malloc(sizeof(struct transition)*2);
a[b]->transitions = tptr;
create_trans(tptr, 'u', a[b + 1]);++tptr;
tptr->symb = -1;
b = 25;
b += 1;
a[b]->value = 508603;
tptr = malloc(sizeof(struct transition)*2);
a[b]->transitions = tptr;
create_trans(tptr, 'X', a[b + 1]);++tptr;
tptr->symb = -1;
b = 26;
b += 1;
a[b]->value = 137879;
tptr = malloc(sizeof(struct transition)*1);
a[b]->transitions = tptr;
tptr->symb = -1;
b = 12;
b += 1;
a[b]->value = 474176;
tptr = malloc(sizeof(struct transition)*3);
a[b]->transitions = tptr;
create_trans(tptr, 'z', a[b + 1]);++tptr;
create_trans(tptr, 'L', a[b + 8]);++tptr;
tptr->symb = -1;
b = 13;
b += 1;
a[b]->value = 380535;
tptr = malloc(sizeof(struct transition)*3);
a[b]->transitions = tptr;
create_trans(tptr, 'i', a[b + 4]);++tptr;
create_trans(tptr, 'l', a[b + 1]);++tptr;
tptr->symb = -1;
b = 14;
b += 4;
a[b]->value = 610171;
tptr = malloc(sizeof(struct transition)*3);
a[b]->transitions = tptr;
create_trans(tptr, 'W', a[b + 1]);++tptr;
create_trans(tptr, 'F', a[b + 2]);++tptr;
tptr->symb = -1;
b = 18;
b += 1;
a[b]->value = 766364;
tptr = malloc(sizeof(struct transition)*1);
a[b]->transitions = tptr;
tptr->symb = -1;
b = 18;
b += 2;
a[b]->value = 643295;
tptr = malloc(sizeof(struct transition)*1);
a[b]->transitions = tptr;
tptr->symb = -1;
b = 14;
b += 1;
a[b]->value = 725387;
tptr = malloc(sizeof(struct transition)*3);
a[b]->transitions = tptr;
create_trans(tptr, 'S', a[b + 1]);++tptr;
create_trans(tptr, 'N', a[b + 2]);++tptr;
tptr->symb = -1;
b = 15;
b += 1;
a[b]->value = 52166;
tptr = malloc(sizeof(struct transition)*1);
a[b]->transitions = tptr;
tptr->symb = -1;
b = 15;
b += 2;
a[b]->value = 603806;
tptr = malloc(sizeof(struct transition)*1);
a[b]->transitions = tptr;
tptr->symb = -1;
b = 13;
b += 8;
a[b]->value = 350777;
tptr = malloc(sizeof(struct transition)*2);
a[b]->transitions = tptr;
create_trans(tptr, 'B', a[b + 1]);++tptr;
tptr->symb = -1;
b = 21;
b += 1;
a[b]->value = 248293;
tptr = malloc(sizeof(struct transition)*2);
a[b]->transitions = tptr;
create_trans(tptr, 'd', a[b + 1]);++tptr;
tptr->symb = -1;
b = 22;
b += 1;
a[b]->value = 108914;
tptr = malloc(sizeof(struct transition)*1);
a[b]->transitions = tptr;
tptr->symb = -1;

    init_state = a[0];
    error_state.value = -1;
    error_state.transitions = NULL;
}

struct state * get_next_state(struct state *current, char symbol){
    struct transition *current_t = current->transitions;
    if (current_t == NULL){
        return current;
    }
    while (current_t->symb != -1){
        if (current_t->symb == symbol){
            return current_t->next;
        }
        current_t++;
    }
    return &error_state;
}

int main(int argc, char **argv){
    if (argc < 2){
        puts("Usage: <program> key");
        return 1;
    }
    int key_length = strlen(argv[1]);
    int i;
    init_states();
    struct state *current_state = init_state;
    for(i=0; i < key_length; ++i){
        current_state = get_next_state(current_state, argv[1][i]);
    }
    if(current_state->value != 0xCADE7){
        puts("O,_,O");
    }else{
        puts("You win!");
    }
    return 0;
}
answer: 

Назад