#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define OFN "D:\原文件.txt"
#define EFN "D:\加密文件.txt"
#define DFN "D:\解密文件.txt"
char y[650],m[650],jm[650];//分别为原文件字符,加密文件字符,解密文件字符
int yb=0,mb=0,jmb=0;//分别为原文件下标,加密文件下标,解密文件下标
int h=1;//密码属性,初始为1
void f()
{
FILE* fp1;
FILE* fp2;
char c;
fp1=fopen("D:\t.txt","r");
fp2=fopen("D:\t2.txt","w");
if(fp1==NULL||fp2==NULL)
{
printf("文件打开失败!\n");
return;
}
else
{
while(c!=EOF)
{
c = fgetc (fp1);
fputc(c, fp2);
}
}
fclose(fp1);
fclose(fp2);
}
void en()
{
FILE* fp1;
FILE* fp2;
char c;
h=1;
fp1=fopen("D:\t.txt","r");
fp2=fopen("D:\t2.txt","w");
if(fp1==NULL||fp2==NULL)
{
printf("文件打开失败!\n");
return;
}
else
{
while(c!=EOF)
{
c = fgetc (fp1);
y[yb]=c;yb++;
h++;
/if(c==' '||c=='z'||c=='9'||c=='0'||c=='a'||c=='.')//遇到指定字符更改密码属性
{
h--;
}/
fputc(c+h, fp2);
m[mb] =c+h;mb++;
}
y[yb+1]='\0';
m[mb+1]='\0';
}
fclose(fp1);
fclose(fp2);
printf("原文为:\n");
puts(y);
printf("密文为:\n");
puts(m);
}
void de()
{
FILE* fp1;
FILE* fp2;
char c;
h=1;
fp1=fopen("D:\t2.txt","r");
fp2=fopen("D:\t3.txt","w");
if(fp1==NULL||fp2==NULL)
{
printf("文件打开失败!\n");
return;
}
else
{
while(c!=EOF)
{
c = fgetc (fp1);
y[yb]=c;yb++;
h++;
/if(c==' '||c=='z'||c=='9'||c=='0'||c=='a'||c=='.')//遇到指定字符重置密码属性
{
h--;
}/
fputc(c-h, fp2);
jm[jmb] =c-h;jmb++;
}
//y[yb+1]='\0';
jm[jmb+1]='\0';
}
fclose(fp1);
fclose(fp2);
printf("密文为:\n");
puts(m);
printf("解密文为:\n");
puts(jm);
int k;
/*for(k=0;k<jmb;k++)
{
printf("%c",jm[k]);
}/**/
//printf("%s",jm);
}
int main()
{
int choice;
int n=250;
while(n--)
{
//system("cls");
printf("欢迎使用文件加密系统!\n");
printf("请输入您的选择\n");
printf("1.加密文件 2.解密文件 3.退出系统\n");
scanf("%d",&choice);
switch (choice)
{
case 1:
en();
break;
case 2:
de();
break;
case 3:
printf("非常感谢您的使用!期待与您下次相见\n");
default:
printf("输入选择有误!请重新输入:");
scanf("%d",&choice);
break;
}
}
system("pause");
return 0;
}