#define _CRT_SECURE_NO_WARNINGS//关闭安全检查
#include<stdio.h>
#include<stdlib.h>
char jia(char ch)
{
return ch + 1;//可以使用位加密return ch^523;
}
char jie(char ch)
{
return ch - 1;//可以使用位解密return ch^523;
}
void jiami(char *path, char *pathjia)
{
FILE *pfr, *pfw;
pfr = fopen(path, "r");//读取
pfw = fopen(pathjia, "w");//写入
if (pfr == NULL || pfw == NULL)
{
printf("失败");
}
else
{
while (!feof(pfr))//feof,文件结束返回1,否则返回0,前面加上!效果相反
{
char ch = fgetc(pfr);//读取字符
putchar(ch);
fputc(jia(ch), pfw);//写入加密字符
}
fclose(pfr);
fclose(pfw);
}
}
void jiemi(char *path, char *pathjie)
{
FILE *pfw, *pfr;
pfw = fopen(path, "r");
pfr = fopen(pathjie, "w");
if (pfr == NULL || pfw == NULL)
{
printf("解密失败");
}
else
{
while (!feof(pfw))
{
char ch = fgetc(pfw);
putchar(ch);
fputc(jie(ch), pfr);
}
fclose(pfw);
fclose(pfr);
}
}
void main()
{
char *path = "C:\\Users\\snail\\Desktop\\1.txt";
char *pathjia = "C:\\Users\\wh\\Desktop\\jiami.txt";
char *pathjie = "C:\\Users\\wh\\Desktop\\jiemi.txt";
jiami(path, pathjia);
jiemi(pathjia, pathjie);
system("pause");
}
简单的文件加密
最新推荐文章于 2024-10-10 10:32:30 发布