diff options
| author | Benedict <benedict@0xb8000.de> | 2016-03-01 20:17:25 +0100 |
|---|---|---|
| committer | Benedict <benedict@0xb8000.de> | 2017-02-21 13:00:24 +0100 |
| commit | 602197a248f3d6ffe5125d5fbaf9c8f87df3c6c5 (patch) | |
| tree | 5391bffd3764d8d85ee9207bf878f9ac5b887775 /task1_hex_to_base64.c | |
| parent | 5b58fc19fafa20a1e24f48e011ddc36d36dfe089 (diff) | |
set 1, challenge 2 finished
Diffstat (limited to 'task1_hex_to_base64.c')
| -rw-r--r-- | task1_hex_to_base64.c | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/task1_hex_to_base64.c b/task1_hex_to_base64.c index 53b98e3..9871055 100644 --- a/task1_hex_to_base64.c +++ b/task1_hex_to_base64.c @@ -168,29 +168,32 @@ int convert_to_base64(char *encode, char *result) } -void xor_string(char *str1, char* str2, char *result) { - int length = strlen(str1); +void xor_string(char *str1, char* str2, char *result, int length) { int i; + for(i=0;i<length;i++) result[i] = str1[i] ^ str2[i]; return; } - -void hex_binary_to_string(char *str1, char *result) +/** + * results must be to times bigger than str1 + */ +void hex_binary_to_string(char *str1, char *result, int length) { int i; - int length = strlen(str1); int tmp = 0; - for(i=0;i<length;i++) { + for(i=0;i<length/2;i++) { tmp = str1[i] & 0xF0; tmp = tmp >> 4; - result[i] = hex_encode[tmp]; + result[i*2] = hex_encode[tmp]; tmp = str1[i] & 0x0F; - result[i+1] = hex_encode[tmp]; + result[(i*2)+1] = hex_encode[tmp]; } + + result[i*2] = '\0'; } int main(int argc, char **argv) @@ -204,14 +207,23 @@ int main(int argc, char **argv) char *back_hex = malloc(length); int i = convert_hex_string_to_binary(argv[1], tmp); int j = convert_hex_string_to_binary(argv[2], tmp2); - xor_string(tmp, tmp2, __xor_string); - hex_binary_to_string(tmp2, back_hex); + xor_string(tmp, tmp2, __xor_string, strlen(argv[2])); + // convert the __xor_string to printable charaters + hex_binary_to_string(tmp2, back_hex, strlen(argv[2])); + printf("input string 1:\n"); + printf("%s\n", argv[1]); + printf("input string 2:\n"); + printf("%s\n", argv[2]); + /* + printf("char string of arg 1:\n"); printf("%s\n", tmp); + printf("char string of arg 2:\n"); printf("%s\n", tmp2); - printf("%s\n", argv[2]); + */ + printf("string 2 from hex back to printable charaters:\n"); + printf("%s\n", back_hex); + printf("xor string:\n"); + hex_binary_to_string(__xor_string, back_hex, strlen(argv[2])); printf("%s\n", back_hex); - printf("%s\n", __xor_string); - convert_to_base64(tmp, base64); - //printf("%s\n", base64); } } |
