主题:[原创]也来个加密程序
我也来发个小加密程序此加密对回车不是支持的很好:(
#include <stdlib.h>
#include<stdio.h>
int jiami();
int jiemi();
int display();
void main()
{
int choice=1;
while(choice!=4)
{
system("cls.exe");
printf("\t\t请选择你要做的操作:\n");
printf("\t\t\t1.加密文件\n");
printf("\t\t\t2.解密文件\n");
printf("\t\t\t3.显示文件\n");
printf("\t\t\t4.退出\n");
printf("\t\t请键入你的选择:");
scanf("%d",&choice);
if(choice==1)
jiami();
else if(choice==2)
jiemi();
else if(choice==3)
{ display();
getchar();
getchar();
}
}
}
int jiami()
{
FILE *fp;
char filename[100],ch,ch1;
int i=0,j=0;
printf("请输入要加密的文件:");
scanf("%s",filename) ;
if((fp=fopen(filename,"r+"))==NULL)
{
printf("\nerror opening file");
return 0;
}
while(!feof(fp))
{
ch=fgetc(fp);
j++;
}
rewind(fp);
while(i<j-1)
{
ch=fgetc(fp);
ch=ch+6;
fseek(fp,i,0);
fputc(ch,fp);
i++;
fseek(fp,i,0);
}
//printf("%c",ch=fgetc(fp));
fclose(fp);
}
int jiemi()
{
FILE *fp;
char filename[100],ch,ch1;
int i=0,j=0;
printf("请输入要解密的文件:");
scanf("%s",filename) ;
if((fp=fopen(filename,"r+"))==NULL)
{
printf("\nerror opening file");
return 0;
}
while(!feof(fp))
{
ch=fgetc(fp);
j++;
}
rewind(fp);
while(i<j-1)
{
ch=fgetc(fp);
ch=ch-6;
fseek(fp,i,0);
fputc(ch,fp);
i++;
fseek(fp,i,0);
}
//printf("%c",ch=fgetc(fp));
fclose(fp);
}
int display()
{
FILE *fp;
char filename[100],ch,ch1;
int i=0,j=0;
printf("请输入要显示的文件:");
scanf("%s",filename) ;
if((fp=fopen(filename,"r+"))==NULL)
{
printf("\nerror opening file");
return 0;
}
while(!feof(fp))
{
ch=fgetc(fp);
j++;
}
rewind(fp);
while(!feof(fp))
{
putchar(fgetc(fp));
}
//printf("%c",ch=fgetc(fp));
fclose(fp);
}
#include <stdlib.h>
#include<stdio.h>
int jiami();
int jiemi();
int display();
void main()
{
int choice=1;
while(choice!=4)
{
system("cls.exe");
printf("\t\t请选择你要做的操作:\n");
printf("\t\t\t1.加密文件\n");
printf("\t\t\t2.解密文件\n");
printf("\t\t\t3.显示文件\n");
printf("\t\t\t4.退出\n");
printf("\t\t请键入你的选择:");
scanf("%d",&choice);
if(choice==1)
jiami();
else if(choice==2)
jiemi();
else if(choice==3)
{ display();
getchar();
getchar();
}
}
}
int jiami()
{
FILE *fp;
char filename[100],ch,ch1;
int i=0,j=0;
printf("请输入要加密的文件:");
scanf("%s",filename) ;
if((fp=fopen(filename,"r+"))==NULL)
{
printf("\nerror opening file");
return 0;
}
while(!feof(fp))
{
ch=fgetc(fp);
j++;
}
rewind(fp);
while(i<j-1)
{
ch=fgetc(fp);
ch=ch+6;
fseek(fp,i,0);
fputc(ch,fp);
i++;
fseek(fp,i,0);
}
//printf("%c",ch=fgetc(fp));
fclose(fp);
}
int jiemi()
{
FILE *fp;
char filename[100],ch,ch1;
int i=0,j=0;
printf("请输入要解密的文件:");
scanf("%s",filename) ;
if((fp=fopen(filename,"r+"))==NULL)
{
printf("\nerror opening file");
return 0;
}
while(!feof(fp))
{
ch=fgetc(fp);
j++;
}
rewind(fp);
while(i<j-1)
{
ch=fgetc(fp);
ch=ch-6;
fseek(fp,i,0);
fputc(ch,fp);
i++;
fseek(fp,i,0);
}
//printf("%c",ch=fgetc(fp));
fclose(fp);
}
int display()
{
FILE *fp;
char filename[100],ch,ch1;
int i=0,j=0;
printf("请输入要显示的文件:");
scanf("%s",filename) ;
if((fp=fopen(filename,"r+"))==NULL)
{
printf("\nerror opening file");
return 0;
}
while(!feof(fp))
{
ch=fgetc(fp);
j++;
}
rewind(fp);
while(!feof(fp))
{
putchar(fgetc(fp));
}
//printf("%c",ch=fgetc(fp));
fclose(fp);
}