diff options
Diffstat (limited to 'lib.c')
| -rw-r--r-- | lib.c | 20 |
1 files changed, 15 insertions, 5 deletions
@@ -90,7 +90,7 @@ static void three_bytes_to_base64(char * encode, int bytes_to_print, char *resul * Transform four base64 encoded characters back to three bytes */ -void decode_base64(char *string1, char *result) +void decode_four_base64_byte(char *string1, char *result) { char one, two, three, tmp; // first byte is first six bits of base64 one and 2 bit of base64 second @@ -113,6 +113,16 @@ void decode_base64(char *string1, char *result) printf("%c%c%c", one, two, three); } +void decode_base64(char *string1, char *result) +{ + int i; + + for(i=0;i<strlen(string1)-3;i++) { + decode_four_base64_byte(&string1[i*4], &result[i*3]); + } + // TODO handle = in base64 at the end +} + static char string_to_hex_map[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}; @@ -203,12 +213,12 @@ static void two_char_hex(char *start, char *result) * @param key * @param result buffer where the result is stored */ -void xor_string(char *str1, char *key, char *result) +void xor_string(char *str1, char *key, char *result, int length_key, int length_str1) { int i, j; - int length_key = strlen(key); + //int length_key = strlen(key); - for(i=0, j=0;i<strlen(str1);i++,j++) { + for(i=0, j=0;i<length_str1;i++,j++) { if (j >= length_key) j = 0; @@ -364,7 +374,7 @@ int brute_force_single_byte_xor(char *string, int length, char* keys) for(i=1;i<255;i++) { single_byte_key = (char) i; - xor_string(string, &single_byte_key, xor_tmp); + xor_string(string, &single_byte_key, xor_tmp, 1, length); if (string_looks_like_it_is_human_language(xor_tmp, length)) { keys[number_found_keys++] = single_byte_key; printf("%s\n", xor_tmp); |
