admin管理员组文章数量:1639834
加密
#include<stdio.h> #include<string.h> void code(char *p,size_t n) { size_t i; for(i = 0; i < n; i++) { p[i] += 3; } } int main() { FILE *p1 = fopen("./a.txt","r"); FILE *p2 = fopen("./b.txt","w"); char buf[1024] = {0}; while(!feof(p1)) { memset(buf,0,sizeof(buf)); size_t res = fread(buf,sizeof(char),sizeof(buf),p1); code(buf,res); fwrite(buf,sizeof(char),res,p2); } fclose(p1); fclose(p2); return 0; }
解密:
/*** decode.c ***/ #include<stdio.h> #include<string.h> void decode(char *p,size_t n) { size_t i; for(i = 0; i < n; i++) { p[i] -= 3; } } int main() { FILE *p1 = fopen("./b.txt","rb"); FILE *p2 = fopen("./c.txt","wb"); char buf[1024] = {0}; while(!feof(p1)) { memset(buf,0,sizeof(buf)); size_t res = fread(buf,sizeof(char),sizeof(buf),p1); decode(buf,res); fwrite(buf,sizeof(char),res,p2); } fclose(p1); fclose(p2); return 0; }
转载于:https://wwwblogs/wanghao-boke/p/11222972.html
版权声明:本文标题:文件操作(二进制文件加密解密) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1729293251a1194429.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论