I am trying to read 16 bytes at a time from a file, and every 16 bytes must be encrypted and written to an output file. Assuming the encryption function shift_encrypt
is working, how can I apply it to 16 bytes at time. Currently I am attempting to store the bytes in an array plaintext
but it is not working
void encryption(char filename[MAX_PATH_LEN], char password[CIPHER_BLOCK_SIZE + 1]) {
char output[256];
snprintf(output, sizeof(output), "%s.ecb", filename);
FILE *output_stream = fopen(output, "wb");
if (output_stream == NULL) {
perror(output);
}
FILE *input_stream = fopen(filename, "rb");
if (input_stream == NULL) {
perror(filename);
}
char plaintext[17];
while (fread(plaintext, 16, 1, input_stream) != 0) {
fwrite(shift_encrypt(plaintext, password), 16, 1, output_stream);
}
fclose(output_stream);
}