I am implementing a Feistel cipher of block size 16 bits. I read from an input file into an integer (32bits), encrypt and write to output file.
unsigned int buf1, buf2;
FILE *fin = fopen("input", "r");
FILE *fout = fopen("output", "w");
while(!feof(fin)) {
fread(&buf1, 4, 1, fin);
buf2 = encrypt(buf1);
fwrite(&buf2, 4, 1, fout);
}
The program is almost done. The only problem is that encryption followed by decryption is not the source file. They're almost same but the difference is only in the last bits. My question is what happens if the no of bytes in the file is not a multiple of 4. What will happen to the last call to fread()?