#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

#define BLOCK_SIZE 256

int main(void) {
	
	FILE* d1;
	FILE* d3;
	FILE* d4;
	FILE* d5;
	d1 = fopen("d1.img", "rb");
	d3 = fopen("d3.img", "rb");
	d4 = fopen("d4.img", "rb");
	d5 = fopen("d5.img", "rb");

	uint8_t data1[BLOCK_SIZE];
	uint8_t data3[BLOCK_SIZE];
	uint8_t data4[BLOCK_SIZE];
	uint8_t data5[BLOCK_SIZE];

	FILE* d2;
	d2 = fopen("d2.img", "wb");

	uint8_t data2[BLOCK_SIZE];

	for (int size = 0; size < 32; size++) {
		
		fread(data1, sizeof(uint8_t), BLOCK_SIZE, d1);
		fread(data3, sizeof(uint8_t), BLOCK_SIZE, d3);
		fread(data4, sizeof(uint8_t), BLOCK_SIZE, d4);
		fread(data5, sizeof(uint8_t), BLOCK_SIZE, d5);

		for (int i = 0; i < BLOCK_SIZE; i++) {
			
			data2[i] = (data1[i] ^ data3[i] ^ data4[i] ^ data5[i]);

		}

		fwrite(data2, sizeof(uint8_t), BLOCK_SIZE, d2);

	}
	
	return 0;

}