diff options
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | task4.c | 2 | ||||
| -rw-r--r-- | task5.c | 2 | ||||
| -rw-r--r-- | task6.c | 46 |
4 files changed, 42 insertions, 12 deletions
@@ -1,7 +1,7 @@ LIB=lib.c CC=gcc -all: task1 task4 task5 task6 +all: task1 task2 task4 task5 task6 task1: $(CC) task1.c $(LIB) -o task1 @@ -19,4 +19,4 @@ task6: $(CC) task6.c $(LIB) -o task6 clean: - rm task4 task5 task6 + rm task1 task2 task4 task5 task6 @@ -29,7 +29,7 @@ void main() { printf("line %i:\n", line_number); for(j=0;j<length;j++) { single_key = keys[j]; - xor_string(string2, &single_key, cleartext); + xor_string(string2, &single_key, cleartext, 1, 60); printf("%s\n", cleartext); } } @@ -9,7 +9,7 @@ void main() char *result = malloc(strlen(stanze)); char *printable = malloc(strlen(stanze)*5); - xor_string(stanze, "ICE", result); + xor_string(stanze, "ICE", result, 3, strlen(stanze)); hex_binary_to_string(result, printable, 2*strlen(stanze)); printf("%s\n", printable); } @@ -2,20 +2,50 @@ void main() { - FILE *fp; + /*FILE *fp; int keysize; + char *file_content, *chipertext, *block1, *block2; + int file_size = 61; + int min_hamming_distance; + fp = fopen("6.txt", "r"); - // data come on stdin (base64 decoded already) + if (fp == NULL) { + printf("Error open file\n"); + exit(1); + } + + file_content = malloc(file_size); + + // read data and decode it from base64 + // result is not a hex strin or? + + while (fscanf(fp, "%60c", file_content) != EOF) { + file_size += 61; + file_content = realloc(file_content, file_size); + } + + ciphertext = malloc(file_size); + decode_base64(file_content, ciphertext); + block1 = malloc(41); + block2 = malloc(41); + + // split ciphertext in blocks of size 2 to 40 for(keysize=2; keysize < 40; keysize++) { - char *string1 = malloc(keysize+1); - char *string2 = malloc(keysize+1); - - //while(fscanf(fp, "%n" + strncpy(block1, ciphertext, keysize); + strncpy(block2, &ciphertext[keysize+1], keysize); - free(string1); - free(string2); + tmp = hamming_distance(block1, block2); + tmp = tmp / keysize; + if (tmp < min_hamming_distance) + min_hamming_distance = tmp; } + + printf("keysize: %i\n", min_hamming_distance); + + + // transpose the blocks +*/ } |
