文件加密:
#include<stdio.h> #include<string.h> #include<stdlib.h> void code(char *s) { while(*s) { (*s)++; s++; } } int main() { char s[1024] = {0}; FILE *p = fopen("/home/exbot/wangqinghe/C/20190716/file.txt","r"); FILE *p1 = fopen("/home/exbot/wangqinghe/C/20190716/b.txt","w"); while(!feof(p)) { memset(s,0,sizeof(s)); fgets(s,sizeof(s),p); code(s); fputs(s,p1); } fclose(p); fclose(p1); return 0; }
文件解密:
#include<stdio.h> #include<string.h> #include<stdlib.h> void decode(char *s) { while(*s) { (*s)--; s++; } } int main() { char s[1024] = {0}; FILE *p = fopen("/home/exbot/wangqinghe/C/20190716/b.txt","r"); FILE *p1 = fopen("/home/exbot/wangqinghe/C/20190716/a.txt","w"); while(!feof(p)) { memset(s,0,sizeof(s)); fgets(s,sizeof(s),p); decode(s); fputs(s,p1); } fclose(p); fclose(p1); return 0; }