diff options
| author | Benedict <benedict@0xb8000.de> | 2016-03-22 19:11:22 +0100 |
|---|---|---|
| committer | Benedict <benedict@0xb8000.de> | 2017-02-21 13:00:25 +0100 |
| commit | 4ed371cc378a3b579d46ed89a2677769a6d5ea24 (patch) | |
| tree | 9e9bb09f2798954540bc62d452258a74923c5e8d /set1 | |
| parent | b586255b0dc1d6940c4a552a7125c9875e8adba6 (diff) | |
completed set 2 challenge 11
Diffstat (limited to 'set1')
| -rw-r--r-- | set1/task1.c | 3 | ||||
| -rw-r--r-- | set1/task8.c | 27 |
2 files changed, 6 insertions, 24 deletions
diff --git a/set1/task1.c b/set1/task1.c index 945964a..7d2a87a 100644 --- a/set1/task1.c +++ b/set1/task1.c @@ -6,12 +6,11 @@ int main(int argc, char **argv) if (argc != 2) return 0; - char *result = malloc(strlen(argv[1])); char *base64 = malloc(strlen(argv[1])); decode_hex_string(argv[1], result); - encode_to_base64(result, base64); + encode_to_base64(result, strlen(argv[1])/2, base64); printf("%s\n", base64); diff --git a/set1/task8.c b/set1/task8.c index 98b3380..d3aa8a8 100644 --- a/set1/task8.c +++ b/set1/task8.c @@ -4,9 +4,9 @@ int main(int arc, char **argv) { // detect AEC in ECB mode, do NOT break it - int number_blocks, i, j, k, read = 0; + int read = 0; size_t len = 0; - int max_hits = 0, hits = 0, line_number= 0, aes_ecb_line = 0; + int line_number= 0, aes_ecb_line = 0; char *line_hex = NULL; // read file FILE *f = fopen("8.txt", "r"); @@ -19,29 +19,12 @@ int main(int arc, char **argv) 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; + printf("line %i: ", line_number); + if (string_is_ecb_encrypted(line, read/2+1, 16)) { aes_ecb_line = line_number; } line_number++; - hits = 0; free(line_hex); free(line); // set line and len to null @@ -49,7 +32,7 @@ int main(int arc, char **argv) len = 0; } - printf("found AES-128-ECB at line: %i\n with %i hits", aes_ecb_line, max_hits); + printf("found AES-128-ECB at line: %i\n", aes_ecb_line); return 0; } |
