diff --git a/brute-force-is-useless b/brute-force-is-useless new file mode 100644 index 0000000..f9e62e8 --- /dev/null +++ b/brute-force-is-useless @@ -0,0 +1,47 @@ +// Proof that brute force is useless. It can crack the word retoor in 8 seconds in best conditions. +// If it takes 8 seconds in the web, how long would it take for web? +// I wouldn't worry too much about your password at all. + + +#include +#include +#include +#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] : "retoor"; + 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; +}