summaryrefslogtreecommitdiff
path: root/set1
diff options
context:
space:
mode:
Diffstat (limited to 'set1')
-rw-r--r--set1/task6.c53
1 files changed, 8 insertions, 45 deletions
diff --git a/set1/task6.c b/set1/task6.c
index 7055044..10e19b2 100644
--- a/set1/task6.c
+++ b/set1/task6.c
@@ -27,56 +27,19 @@ char **transpose_blocks(char *ciphertext, int blocksize, int length)
return blocks;
}
+
int main()
{
- FILE *fp;
int keysize;
- char ch;
- char *file_content, *new_file_content, *chiphertext, *block1, *block2;
- int file_size = 60, file_pos = 0;
- int i;
+ char *chiphertext, *block1, *block2;
+ char *file_content;
+ int i, file_length;
double min_hamming_distance, tmp;
+ int ciphertext_len;
- fp = fopen("6.txt", "r");
-
- if (fp == NULL) {
- printf("Error open file\n");
- exit(1);
- }
-
- file_content = malloc(file_size);
-
- if (file_content == NULL) {
- perror("out of memory");
- exit(1);
- }
-
- // read data and decode it from base64
- // result is not a hex strin or?
-
- while ( (ch = fgetc(fp)) != EOF) {
- // ignore new lines as this is part of base64
- if (ch == '\n' || ch == '\r')
- continue;
-
- if (file_pos+1 >= file_size) {
- new_file_content = realloc(file_content, (file_size+60));
- if (new_file_content != NULL) {
- file_content = new_file_content;
- file_size += 60;
- }
- else {
- printf("error allocating memory\n");
- exit(1);
- }
- }
- file_content[file_pos++] = ch;
- }
- file_content[file_pos] = '\0';
-
- int ciphertext_len = 0;
-
- chiphertext = malloc(file_pos+1);
+ file_length = read_base64_file("6.txt", &file_content);
+ printf("read: %i, address: %p\n", file_length, file_content);
+ chiphertext = malloc(file_length+1);
ciphertext_len = decode_base64(file_content, chiphertext);
block1 = malloc(41);