This repository has been archived by the owner on Jul 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.c
69 lines (51 loc) · 1.57 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "md5.h"
#define START 0x20
#define END 0x7E
int compare (const uint32_t a[], const uint32_t b[]) {
return a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3];
}
int brute_force_fixed_length (const uint32_t hash[4], byte_t* result, byte_t* test, int p, int len) {
static md5_t MD5;
static uint32_t check[4];
byte_t c;
if (p < len-1) {
for (c = START; c <= END; ++c) {
test[p] = c;
if (brute_force_fixed_length(hash, result, test, p + 1, len))
return 1;
}
} else {
for (c = START; c <= END; ++c) {
test[p] = c;
md5_init(&MD5);
md5_update(&MD5, test, len);
md5_hash(&MD5, check);
if (compare(hash, check)) {
strcpy(result, test);
return 1;
}
}
}
return 0;
}
int brute_force (const uint32_t hash[4], byte_t* result, int maxlen) {
byte_t str[maxlen+1];
for (int i = 0; i < maxlen; i++)
if (brute_force_fixed_length (hash, result, str, 0, i)) return 1;
return 0;
}
int main() {
uint32_t hash[4];
char hexstring[33] = {0};
char result[11];
printf("Enter hex hash: ");
fgets(hexstring, 33, stdin);
for (int i = 0; i < 4; i++) sscanf(&hexstring[i * 8], "%8x", &hash[i]);
printf("Decrypting hash: %08x%08x%08x%08x\n", hash[0], hash[1], hash[2], hash[3]);
brute_force(hash, result, 10);
printf("Original text: %s\n", result);
return 0;
}