Last active
July 13, 2016 19:04
-
-
Save svenstaro/d2000b238fce06d2ac275d81cd166237 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*.o | |
*.x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: default clean | |
# declarations # | |
### compiler ### | |
CC = gcc | |
### compilation flags ### | |
#CFLAGS = -g -Wall -Wextra -Werror -Wshadow -Wpedantic | |
CFLAGS = -O3 -lm -Wall -Wextra -Werror -Wshadow -Wpedantic -fopenmp | |
### objects ### | |
OBJ = password_compare.o timing.o | |
### executable ### | |
EXECUTABLE = timing.x | |
# targets # | |
### default target ### | |
# compile executable | |
default: $(EXECUTABLE) | |
### executable target ### | |
$(EXECUTABLE): $(OBJ) | |
$(CC) $(CFLAGS) $(OBJ) -o $(EXECUTABLE) | |
### objects target ### | |
# compile C-files without linking to .o (object) files | |
%.o: %.c | |
$(CC) $(CFLAGS) -c $< -o $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
#include <assert.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <stdbool.h> | |
#include <omp.h> | |
#include "timing.h" | |
#define MAXLEN 4 | |
const char symbols[] = "abcdefghijklmnopqrstuvwxyz" | |
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
/* "0123456789"; */ | |
/* "äöü" */ | |
/* "!@#$%^&*()-_=+[]{}|/?.,<>;:'\"\\`~" */ | |
/* "€´ "; */ | |
void increase_char(uint32_t loc, uint32_t max_len, char str[], uint32_t str_len, const char symbs[], uint32_t symbs_len) { | |
if (loc >= max_len) | |
return; | |
if (str[loc] == symbs[symbs_len - 1]) { | |
str[loc] = symbs[0]; | |
increase_char(loc + 1, max_len, str, str_len, symbs, symbs_len); | |
} else { | |
// Try next character at this location | |
char * ptr_to_char = strchr(symbols, str[loc]); | |
str[loc] = *(ptr_to_char+1); | |
} | |
} | |
int main() { | |
size_t symbols_len = strlen(symbols); | |
for (uint32_t current_length = 1; current_length <= MAXLEN; current_length++) { | |
char test_string[current_length]; | |
memset(test_string, 'a', current_length); | |
uint32_t total_combinations = pow(symbols_len, current_length); | |
printf("current_length: %u, symbols_len: %lu, total_combinations: %u\n", | |
current_length, symbols_len, total_combinations); | |
#pragma omp parallel for | |
for (uint32_t num_combination =1; num_combination <= total_combinations; num_combination++) { | |
/* printf("Trying: %s\n", test_string); */ | |
if (password_compare(test_string) != -1) { | |
printf("Password is %s", test_string); | |
} | |
increase_char(0, current_length, test_string, current_length, symbols, symbols_len); | |
} | |
printf("Unsuccessful :(\n"); | |
} | |
return EXIT_SUCCESS; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <time.h> | |
#include <stdint.h> | |
extern int password_compare(const char * password); | |
uint32_t time_max(const clock_t * arr, uint32_t len); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment