Skip to content

Commit ac2ad7e

Browse files
Create Brute Force
1 parent b1784c2 commit ac2ad7e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Brute Force

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
#include <stdlib.h>
4+
5+
static const char alphabet[] =
6+
"abcdefghijklmnopqrstuvwxyz"
7+
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
8+
"0123456789";
9+
10+
static const int alphabetSize = sizeof(alphabet) - 1;
11+
12+
void bruteImpl(char* str, int index, int maxDepth)
13+
{
14+
for (int i = 0; i < alphabetSize; ++i)
15+
{
16+
str[index] = alphabet[i];
17+
18+
if (index == maxDepth - 1) printf("%s\n", str);
19+
else bruteImpl(str, index + 1, maxDepth);
20+
}
21+
}
22+
23+
void bruteSequential(int maxLen)
24+
{
25+
char* buf = malloc(maxLen + 1);
26+
27+
for (int i = 1; i <= maxLen; ++i)
28+
{
29+
memset(buf, 0, maxLen + 1);
30+
bruteImpl(buf, 0, i);
31+
}
32+
33+
free(buf);
34+
}
35+
36+
int main(void)
37+
{
38+
bruteSequential(3);
39+
return 0;
40+
}

0 commit comments

Comments
 (0)