核心代碼:
char encrypt( char f , char c) { return f^c; }
int OutEncrypt( char *FilePath, char *SecretWord ) { FILE * fp ; FILE * fp1; char *p= FilePath , *s= SecretWord; //char fn[128], *p = fn, ps[10], *s = ps; //fn[128]存放加密文件路徑,ps[10]存放密碼 char ch; char *tm = "C:\\temp.temp"; //存放臨時文件 if(( fp = fopen(p,"rb") )== NULL || ( fp1 = fopen(tm,"wb") ) == NULL ) { return 0; //加密失敗 } ch = fgetc(fp); while( !feof(fp) ) { s = SecretWord; while( *s != '\0' ) { ch = encrypt( ch, *s++ ); fputc( ch, fp1 ); ch = fgetc(fp); } } fclose( fp ); fclose( fp1); remove(p); rename(tm, p); return 1; //加密成功 }