summaryrefslogtreecommitdiff
path: root/set1/task8.c
blob: d3aa8a83fc8edf41821624bef25d64e426948dc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "../lib/lib.h"


int main(int arc, char **argv)
{
	// detect AEC in ECB mode, do NOT break it
	int read = 0;
	size_t len = 0;
	int 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);
		printf("line %i: ", line_number);	
		if (string_is_ecb_encrypted(line, read/2+1, 16)) {
			aes_ecb_line = line_number;
		}
		line_number++;
		free(line_hex);
		free(line);
		// set line and len to null
		line = NULL;
		len = 0;
	}

	printf("found AES-128-ECB at line: %i\n", aes_ecb_line);

	return 0;
}