Add brute-force-is-useless
This commit is contained in:
parent
beb50489d3
commit
a9eab4ace8
47
brute-force-is-useless
Normal file
47
brute-force-is-useless
Normal file
@ -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 <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] : "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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user