加密过程:利用fread函数将文件以一个字节的形式依次读出,对取出的字节进行-1操作,然后再用fwrite函数写入
void testEncrypt(){
FILE *fpRead = fopen("/Users/Lark/Desktop/Test.mp4", "r");
FILE *fpWrite = fopen("/Users/Lark/Desktop/Test.secret", "w");
if (fpRead) {
if (fpWrite) {
while (1) {
if (feof(fpRead)) {
break;
}
char bytes;
fread(&bytes, 1, 1, fpRead);
bytes -= 1;
fwrite(&bytes, 1, 1, fpWrite);
}
printf("加密成功!!!\n");
fclose(fpWrite);
}
fclose(fpRead);
}
}
解密过程:
void declassify(){
FILE *fpRead = fopen("/Users/Lark/Desktop/Test.secret", "r");
FILE *fpWrite = fopen("/Users/Lark/Desktop/Test2.mp4", "w");
if (fpRead) {
if (fpWrite) {
while (1) {
if (feof(fpRead)) {
break;
}
char bytes;
fread(&bytes, 1, 1, fpRead);
bytes += 1;
fwrite(&bytes, 1, 1, fpWrite);
}
printf("解密成功!!!\n");
fclose(fpWrite);
}
fclose(fpRead);
}
}