diff options
| author | Benedict <benedict@0xb8000.de> | 2016-03-19 22:44:50 +0100 |
|---|---|---|
| committer | Benedict <benedict@0xb8000.de> | 2017-02-21 13:00:25 +0100 |
| commit | 95b1e82c4fca864600108d4e36ceadbb290a76f3 (patch) | |
| tree | bb5595e557c90323d5383379143636cf18e01a21 /set1/task8.c | |
| parent | 2930ba4f32680e245c1dae66197153abdf6502a6 (diff) | |
set1, challenge 8 completed
Diffstat (limited to 'set1/task8.c')
| -rw-r--r-- | set1/task8.c | 55 |
1 files changed, 55 insertions, 0 deletions
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<number_blocks;i++) { + for(j=1;j<number_blocks;j++) { + for(k=0;k<16;k++) { + if(line[i*16+k] != line[j*16+k]) + break; + + if ( k == 15) + hits++; + } + } + } + printf("line: %i, hits: %i\n", line_number, hits); + if (hits > 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; +} |
