From ddce9b2d44ab48fc566870c5155b39c8fc06f24d Mon Sep 17 00:00:00 2001 From: Benedict Date: Tue, 21 Feb 2017 12:52:02 +0100 Subject: moved files of set1 into subdir --- set1/task4.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 set1/task4.c (limited to 'set1/task4.c') diff --git a/set1/task4.c b/set1/task4.c new file mode 100644 index 0000000..c95e21f --- /dev/null +++ b/set1/task4.c @@ -0,0 +1,37 @@ + +#include "../lib/lib.h" + +int main() { + /** read the file */ + FILE *fp; + int malloc_size = 62; + int line_number = 0; + int j; + char key; + char *string = malloc(malloc_size); + char *string2 = malloc(malloc_size); + char *cleartext = malloc(malloc_size); + struct key_and_freq tmp; + + fp = fopen("4.txt", "r"); + + if (fp == NULL) { + printf("Error open file\n"); + exit(1); + } + + while (fscanf(fp, "%61c", string) != EOF) { + tmp.hits = 0; + j = decode_hex_string(string, string2); + key = brute_force_single_byte_xor(string2, j, &tmp); + xor_string(string2, &key, cleartext, 1, j); + if ((!isprintable(cleartext, j)) || (tmp.hits < 10)) + continue; + + printf("%s", cleartext); + line_number++; + } + + fclose(fp); + return 0; +} -- cgit v1.2.3-70-g09d2