summaryrefslogtreecommitdiff
path: root/task6.c
diff options
context:
space:
mode:
authorBenedict <benedict@0xb8000.de>2016-03-04 12:45:40 +0100
committerBenedict <benedict@0xb8000.de>2017-02-21 13:00:24 +0100
commit14e3b0e4f801f6fdbd6be941a2022e4e665d88eb (patch)
treee3707cc56c16aa8a38d85c3eb1947ba4188316e3 /task6.c
parent9db81cb91674d45bbb4936a098f4e4fb1a5b45bd (diff)
fxied api change in other tasks
Diffstat (limited to 'task6.c')
-rw-r--r--task6.c46
1 files changed, 38 insertions, 8 deletions
diff --git a/task6.c b/task6.c
index d807b69..aff1d39 100644
--- a/task6.c
+++ b/task6.c
@@ -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
+*/
}