From 4ed371cc378a3b579d46ed89a2677769a6d5ea24 Mon Sep 17 00:00:00 2001 From: Benedict Date: Tue, 22 Mar 2016 19:11:22 +0100 Subject: completed set 2 challenge 11 --- lib/lib.c | 50 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 8 deletions(-) (limited to 'lib/lib.c') diff --git a/lib/lib.c b/lib/lib.c index 0eb5be8..7c8beae 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -81,7 +81,6 @@ static void three_bytes_to_base64(char * encode, int bytes_to_print, char *resul // last six bit11s four = encode[2] & 0x3F; ret[3] = base64_encode[four]; - ret[4] = '\0'; if(bytes_to_print-- > 0) result[3] = ret[3]; } @@ -378,12 +377,11 @@ static int frequent_histogramm_matchs(char *string, int length) * encode the given string into base64 and stores it in result */ -void encode_to_base64(char *encode, char *result) +void encode_to_base64(char *encode, int length_encode, char *result) { - int length = strlen(encode); - int rounds = length / 3; - int bytes_last_round = length % 3; + int rounds = length_encode / 3; + int bytes_last_round = length_encode % 3; int i; for (i=0;i 0) { - three_bytes_to_base64(encode + i*3, 1+bytes_last_round, &result[i*4]); + three_bytes_to_base64(&encode[i*3], (4-bytes_last_round), &result[i*4]); - for(i=0;i<(3-bytes_last_round);i++) - result[i*4+(1+bytes_last_round)] = '='; + for(i=bytes_last_round;i>=0;i--) + result[rounds*4+(4-bytes_last_round)] = '='; + + result[rounds*4+4] = '\0'; } } @@ -522,3 +524,35 @@ int read_base64_file(const char *file, char **out) return file_pos; } + +int count_equal_blocks(char *string, int length_string, int blocksize) +{ + int number_blocks = length_string / blocksize; + printf("number_blocks: %i", number_blocks); + int hits = 0, i, j, k; + + for(i=0;i (length_string/blocksize)); +} + + -- cgit v1.2.3-70-g09d2