summaryrefslogtreecommitdiff
path: root/lib.c
diff options
context:
space:
mode:
authorBenedict <benedict@0xb8000.de>2016-03-04 12:42:08 +0100
committerBenedict <benedict@0xb8000.de>2017-02-21 13:00:24 +0100
commit9db81cb91674d45bbb4936a098f4e4fb1a5b45bd (patch)
tree2f794833dace3df001803f275a23573f35114a7f /lib.c
parentd2e94cb263ab933103e1968c0f3da638f35f5983 (diff)
reimplemented task2
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/lib.c b/lib.c
index 4d0d769..252deb2 100644
--- a/lib.c
+++ b/lib.c
@@ -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);