From 95b1e82c4fca864600108d4e36ceadbb290a76f3 Mon Sep 17 00:00:00 2001 From: Benedict Date: Sat, 19 Mar 2016 22:44:50 +0100 Subject: set1, challenge 8 completed --- set1/Makefile | 6 ++++-- set1/task8.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 set1/task8.c (limited to 'set1') diff --git a/set1/Makefile b/set1/Makefile index 6c0f149..0d08451 100644 --- a/set1/Makefile +++ b/set1/Makefile @@ -2,7 +2,7 @@ LIB=../lib/lib.c CC=gcc CFLAGS := -g -Wall $(CFLAGS) -all: task1 task2 task4 task5 task6 task7 +all: task1 task2 task4 task5 task6 task7 task8 task1: $(CC) $(CFLAGS) task1.c $(LIB) -o task1 @@ -21,5 +21,7 @@ task6: task7: $(CC) $(CFLAGS) task7.c `pkg-config --cflags --libs libcrypto` -o task7 +task8: + $(CC) $(CFLAGS) task8.c $(LIB) -o task8 clean: - rm task1 task2 task4 task5 task6 task7 + rm task1 task2 task4 task5 task6 task7 task8 diff --git a/set1/task8.c b/set1/task8.c new file mode 100644 index 0000000..98b3380 --- /dev/null +++ b/set1/task8.c @@ -0,0 +1,55 @@ +#include "../lib/lib.h" + + +int main(int arc, char **argv) +{ + // detect AEC in ECB mode, do NOT break it + int number_blocks, i, j, k, read = 0; + size_t len = 0; + int max_hits = 0, hits = 0, line_number= 0, aes_ecb_line = 0; + char *line_hex = NULL; + // read file + FILE *f = fopen("8.txt", "r"); + + if (f == NULL) { + perror("failed to open 8.txt"); + exit(1); + } + + while( (read = getline(&line_hex, &len, f)) != -1) { + // line is hex encoded + char *line = malloc(read/2+1); + + decode_hex_string(line_hex, line); + + number_blocks = read / 2 / 16; + // count 16 byte blocks which are equal + for(i=0;i max_hits) { + max_hits = hits; + aes_ecb_line = line_number; + } + line_number++; + hits = 0; + free(line_hex); + free(line); + // set line and len to null + line = NULL; + len = 0; + } + + printf("found AES-128-ECB at line: %i\n with %i hits", aes_ecb_line, max_hits); + + return 0; +} -- cgit v1.2.3-70-g09d2