c语言简单文件加密

来源:互联网 发布:saber软件正版价格 编辑:程序博客网 时间:2024/05/19 19:13

注:此文章是用于记录我学习C语言的笔记。

//加密a.txt中的内容,生成b.txt

#include<stdio.h>#include<string.h>void code(char *s){    while(*s){        (*s)++;        s++;    }}int main(){    char buff[1024];    FILE *file1 = fopen("D:\\a.txt","r");//    FILE * file2 = fopen("D:\\b.txt","w");    while(!feof(file1)){//feof函数是判断读到文件结尾没        fgets(buff,sizeof(file1),file1);//把读取到文件中的内容缓存到buff中        code(buff);//加密缓存中的内容        fputs(buff,file2);//把缓存中的内容存到b.txt文件中    }    fclose(file1);//关闭文件    fclose(file2);}

//解密b.txt中的内容

void decode(char *ss){    while(*ss){        (*ss)--;        ss++;    }}int main(){    char buff[1024];    FILE *file1 = fopen("D:\\b.txt","r");    FILE *file2 = fopen("D:\\c.txt","w");    while(!feof(file1)){        fgets(buff,sizeof(buff),file1);//读取b.txt中的内容到缓存中        decode(buff);//解密        fputs(buff,file2);//把缓存中的内容存到c.txt中    }    fclose(file1);    fclose(file2);}
0 0
原创粉丝点击