SRE/02-Easy2/smallGenerator.c

96 lines
2.5 KiB
C
Raw Permalink Normal View History

2025-02-27 19:27:10 +01:00
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
const uint16_t NBR_PASSWORDS_REQUESTED = 100;
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 == 0x3c3e386b ? 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] = {0x6a, 0x1b, 0x0e, 0x0c};
char password[13];
const uint8_t max_char = sizeof(list);
password[0] = 'r';
password[1] = 'e';
password[2] = 'm';
password[3] = 'i';
uint8_t foo[4];
for(uint16_t n = 0; n < NBR_PASSWORDS_REQUESTED; n++) {
for(uint8_t i = 0; i < 4; i++) {
foo[i] = password[i] ^ mdw[i];
}
for(uint8_t i = 0; i < 4; i++) {
// password[i] = give_char(rand()%max_char);
uint32_t counter = 0;
// for(uint8_t c2 = 0; c2 < max_char; c2++) {
// }
do{
password[i+4] = list[rand()%max_char];
for(uint8_t j = 0; j < max_char; j++) {
password[i+8] = list[j];
if( ((uint8_t)password[i+4] ^ (uint8_t)password[i+8]) == foo[i]) break;
}
counter++;
} while (( (uint8_t)password[i+4] ^ (uint8_t)password[i+8] ) != foo[i]);
//printf("Counter: %zu\n", counter);
}
password[12] = '\0';
if (hash(password)) {
printf("%s\n", password);
} else {
printf("Fuck\n");
}
}
}
// l96n hRI/ npqM 471M
//
//
// 56 25 36 67
// -----------
// 6C 39 36 6E
// 68 52 49 2F
// 6E 70 71 4D
// -----------
// 3c 3e 38 6b