满意答案
zlyzs66
2013.12.19
采纳率:57% 等级:12
已帮助:7406人
//VC++6.0下进行编译
#include
#define N 5
void jiami(char namea[256])
{
FILE *fp_jiami,*fp_file2;
char c;
fp_jiami=fopen(namea,"rb");
fp_file2=fopen("file2.plg","wb");
while(EOF!=(fscanf(fp_jiami,"%c",&c)))
{
if((c>='A'&&c<='Z')||(c>='a'&&c<='z'))
{
c=c+N;
if (!((c>='A'&&c<='Z')||(c>='a'&&c<='z')))c=c-26;
if(c>='a'&&c<='z')c=c-32;
}
fprintf(fp_file2,"%c",c);
}
fclose(fp_file2);
fclose(fp_jiami);
}
void jiemi(char en_name[256])
{
FILE *fp_jiemi,*fp_file3;
char c;
fp_jiemi=fopen(en_name,"rb");
fp_file3=fopen("file3.plg","wb");
while(EOF!=(fscanf(fp_jiemi,"%c",&c)))
{
if((c>='A'&&c<='Z')||(c>='a'&&c<='z'))
{
c=c-N;
if (!((c>='A'&&c<='Z')||(c>='a'&&c<='z')))c=c+26;
if(c>='A'&&c<='Z')c=c+32;
}
fprintf(fp_file3,"%c",c);
}
fclose(fp_file3);
fclose(fp_jiemi);
}
int main()
{
char name[256];
int n;
printf("输入你要操作的TXT文本:");
gets(name);
printf("\n请选择需要进行的操作:\n");
printf(" 1:加密 2:解密 \n");
printf("输入你的选择:");
scanf("%d",&n);
switch(n) {
case 1:{jiami(name);printf("\t加密成功!!\n\n"); break;}
case 2:{jiemi(name);printf("\t解密成功!!\n\n"); break;}
default:{printf("输入操作不存在!");}
}
return 0;
}
00分享举报