-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbruteforce.c
42 lines (34 loc) · 992 Bytes
/
bruteforce.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "rlib.h"
unsigned long gen(char *str, int position, int length, char * expect, unsigned long attempt) {
if (position == length) {
str[position] = '\0';
return attempt;
}
for (char c = 'a'; c <= 'z'; c++) {
str[position] = c;
attempt = gen(str, position + 1, length,expect, attempt + 1);
if(!strcmp(str,expect))
{
return attempt;
}
}
return attempt;
}
int main(int argc, char *argv[]) {
char *str = (char *)malloc((1337) * sizeof(char));
if (str == NULL) {
printf("Memory allocation failed!\n");
return 1;
}
char * needle = argc == 2 ? argv[1] : "raetaoaor";
size_t length = strlen(needle);
RBENCH(1, {
unsigned long attempt = gen(str, 0, length, needle, 0);
printf("Resolved \"%s\" within %zd combinations.\n",needle, attempt);
})
free(str);
return 0;
}