Skip to content

Instantly share code, notes, and snippets.

@John-K
Last active June 5, 2018 05:38
Show Gist options
  • Save John-K/4adf1aca8e311641a6396e72f1f61ef7 to your computer and use it in GitHub Desktop.
Save John-K/4adf1aca8e311641a6396e72f1f61ef7 to your computer and use it in GitHub Desktop.
Reverse Engineering a Book Cover: bruteforcing crc32 values
//gcc -msse4.2 brute.c
#include <stdio.h>
int crc32(int crc, char c) {
return __builtin_ia32_crc32qi(crc, c);
}
int main() {
int value = 0;
int tableIndex = 22;
int table[] = {0x564d94ce,0x56487985,0xcd6966e6,0x791b5538,0xbdc0bfb7,0x8ecbf593,0xc652c4a2,0x94a3ebf7,0x2673b49e,0x89f7731e,0x32c1eb44,0x7886f083,0x52e2bb44,0xc7fdffaa,0x69f9005a,0xe04743ac,0x44229524,0xe8032961,0x8cc30f1e,0x084cdea3,0xeb48d1ad,0x90809740,0xe4292d5a };
char password[24] = {};
char *pwdpos = &password[22];
while (tableIndex >= 0) {
//printf("bruting pos %d...", pwdpos - password);
for (unsigned char c = 0; c < 256; c++) {
int crc = crc32(0, c);
for (char *d = pwdpos+1; d - password <= 22; d++) {
crc = crc32(crc, *d);
}
if (crc == table[tableIndex]) {
//printf("%c\n", c);
*pwdpos-- = c;
--tableIndex;
break;
} else if (c == 255) {
//printf("couldn't determine char for pos %d\n", pwdpos - password);
return -1;
}
}
}
printf("password is '%s'\n", password);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment