In general, that's what happened. Now, however, does not match the title of the topic. I throw the code of the entire file, suddenly someone will come in handy, especially not on the Internet. If there are more ways, please write.
#include "tea.h" void main(int argc, char **argv){ FILE *srcFile, *resultFile; if ((srcFile = fopen("c:/dev/encoding/test.xlsx", "rb")) == NULL) { printf("Cannot open file.\n"); exit(1); } if ((resultFile = fopen("c:/dev/encoding/test.enc", "wb")) == NULL) { printf("Cannot open file.\n"); exit(1); } encodeFile(srcFile, resultFile, "01234567"); fclose(srcFile); fclose(resultFile); if ((srcFile = fopen("c:/dev/encoding/test.enc", "rb")) == NULL) { printf("Cannot open file.\n"); exit(1); } if ((resultFile = fopen("c:/dev/encoding/res.xlsx", "wb")) == NULL) { printf("Cannot open file.\n"); exit(1); } decodeFile(srcFile, resultFile, "01234567"); fclose(srcFile); fclose(resultFile); return 0; } void encodeFile(FILE* srcFile, FILE* resultFile, uint32_t* key){ printf("Start encoding\n"); fseek(srcFile, 0L, SEEK_END); long size = ftell(srcFile); fseek(srcFile, 0L, SEEK_SET); if ((fwrite(&size, sizeof(long), 1, resultFile)) != 1) { printf("Fatal Error writing output file!!!\n"); exit(-1); } char buffer[8]; while (!feof(srcFile)) { fread(buffer, sizeof(char), 8, srcFile); encrypt(buffer, key); if ((fwrite(buffer, sizeof(char), 8, resultFile)) != 8) { printf("Fatal Error writing output file!!!\n"); exit(-1); } } printf("Encoding complete\n"); } void decodeFile(FILE* srcFile, FILE* resultFile, uint32_t* key){ printf("Start decoding\n"); char buffer[8]; long size; fread(&size, sizeof(long), 1, srcFile); printf("%i\n", size); for (size; size > 8; size -= 8){ fread(buffer, sizeof(char), 8, srcFile); decrypt(buffer, key); if ((fwrite(buffer, sizeof(char), 8, resultFile)) != 8) { printf("Fatal Error writing output file!!!\n"); exit(-1); } } fread(buffer, sizeof(char), 8, srcFile); decrypt(buffer, key); if ((fwrite(buffer, sizeof(char), size, resultFile)) != size) { printf("Fatal Error writing output file!!!\n"); exit(-1); } printf("Decoding complete\n"); } void encrypt(uint32_t* v, uint32_t* k){ /* set up */ uint32_t v0 = v[0]; uint32_t v1 = v[1]; uint32_t sum = 0; uint32_t i; /* a key schedule constant */ uint32_t delta = 0x9e3779b9; /* cache key */ uint32_t k0 = k[0]; uint32_t k1 = k[1]; uint32_t k2 = k[2]; uint32_t k3 = k[3]; /* basic cycle start */ for (i = 0; i < 32; i++) { sum += delta; v0 += ((v1 << 4) + k0) ^ (v1 + sum) ^ ((v1 >> 5) + k1); v1 += ((v0 << 4) + k2) ^ (v0 + sum) ^ ((v0 >> 5) + k3); } /* end cycle */ v[0] = v0; v[1] = v1; } void decrypt(uint32_t* v, uint32_t* k){ /* set up */ uint32_t v0 = v[0]; uint32_t v1 = v[1]; uint32_t sum = 0xC6EF3720; uint32_t i; /* a key schedule constant */ uint32_t delta = 0x9e3779b9; /* cache key */ uint32_t k0 = k[0]; uint32_t k1 = k[1]; uint32_t k2 = k[2]; uint32_t k3 = k[3]; /* basic cycle start */ for (i = 0; i < 32; i++) { v1 -= ((v0 << 4) + k2) ^ (v0 + sum) ^ ((v0 >> 5) + k3); v0 -= ((v1 << 4) + k0) ^ (v1 + sum) ^ ((v1 >> 5) + k1); sum -= delta; } /* end cycle */ v[0] = v0; v[1] = v1; }