“纸上得来终觉浅,绝知此事要躬行” 心血来潮,想写一段C语言的程序,实现一个文件的加密,打算采用最简单的加密办法,就是逐个字节取反。 第一次花了一刻钟时间写了如下代码的程序: /* * File encrypter sample */ #include <stdio.h> int main(void) { FILE *fp; FILE *temp; char ch; char ch2; char strFileName[256] = {0}; char cmdBuf[256]={0}; printf("please input file name:"); gets(strFileName); /* open two files */ fp = fopen(strFileName, "rb+"); if(fp == NULL) { printf("/n file: %s open err!/n", strFileName); return -1; } temp = fopen("temp.cry", "wb+"); if(temp == NULL) { printf("/n file create err!/n"); return -1; } /* Encrypter every character, and write it to file */ do { ch = fgetc(fp); ch2 = ~ch; fputc(ch2, temp); }while(ch != EOF); fclose(fp); fclose(temp); /* Del old file *