From 71dec29e71692819d87e4af8088270f92b3f2ab2 Mon Sep 17 00:00:00 2001 From: Krzysztof KWIATKOWSKI Date: Wed, 6 May 2015 00:15:48 +0200 Subject: [PATCH] S1/T2 --- utils/hex_to_base64.cpp | 67 +++++++++++++++++++++++++++++++++++++---- utils/hex_to_base64.h | 5 ++- utils/utils_tester.cpp | 42 +++++++++++++++++++++++++- 3 files changed, 106 insertions(+), 8 deletions(-) diff --git a/utils/hex_to_base64.cpp b/utils/hex_to_base64.cpp index 61e3ac0..43f2e3f 100644 --- a/utils/hex_to_base64.cpp +++ b/utils/hex_to_base64.cpp @@ -51,19 +51,38 @@ struct int24 { unsigned int data:24; }; -void read_bytes(const char* hex_buff, int24& o_data, unsigned len=3) +void convert_string_to_hex(const char* const iArray, const unsigned iArrayLen, unsigned char*& oHexArray) { unsigned char hex; - for(int i=0; i #include #include @@ -44,6 +44,46 @@ void hex_to_base64_text() { assert( strlen(expected_buff4) == strlen(output)); } +void convert_string_to_hex_test() +{ + const char test_buff1[] = "49276d"; + unsigned char out_buff[3]; + unsigned char* p = out_buff; + convert_string_to_hex(test_buff1, strlen(test_buff1), p); + assert( p[0] == 0x49 + && p[1] == 0x27 + && p[2] == 0x6d); + + // and back + char out_buf[6]; + char* op = out_buf; + convert_hex_to_string(p, 3, op); + assert( memcmp(op, test_buff1, 6) == 0 ); + +} + +void xor_strings_test() +{ + const char i_buf_1[] = "1c0111001f010100061a024b53535009181c"; + const char* p_ibuf1=i_buf_1; + + const char i_buf_2[] = "686974207468652062756c6c277320657965"; + const char* p_ibuf2=i_buf_2; + + char out_buf[36]; + char* p_out_buf=out_buf; + + unsigned char buf[36/2]; + unsigned char* p_buf = buf; + + xor_strings(p_ibuf1, p_ibuf2, p_buf); + + convert_hex_to_string(buf, 36/2, p_out_buf); + assert( memcmp(out_buf, "746865206b696420646f6e277420706c6179", 36) == 0); +} + int main() { hex_to_base64_text(); + convert_string_to_hex_test(); + xor_strings_test(); } \ No newline at end of file