jiami.c

来自「能够对文本文件进行加密」· C语言 代码 · 共 74 行

C
74
字号
# include "stdio.h"
# include "stdlib.h"
FILE *fp;
unsigned char xx[500][80],yy[20];
int total=0;
main(int argc,char *argv[])
{
    int i=0,j=0,k=0,l=0;
      if(argc<2){
	printf("\n parameter is null\n usage: jiami c:\\a.txt\n");
	exit(1);
    }
puts("please input correct password:\n");
while(l<3){
for(k=0;(yy[k]=getch())!='\r';k++)
	printf("$");
yy[k]='\0';
if(strcmp(yy,"jiangliyang")!=0)
	{printf("\npassword is wrong\nplease repeat!\n");l++;}
else break;}
if(l>=3){
	puts("sorry,you can't continue!");
	exit(1);
}
    if((fp=fopen(argv[1],"r"))==NULL){
	printf("can't open file!\n");
	exit(1);
    }
    printf("\nreading file.....\n");
   while(!feof(fp)){       /*read in*/
	 fgets(xx[i],80,fp);
	 i++;
    }
   fclose(fp);
   puts("reading file over!");
   printf("the total lines is: %d\n",i);
   total=i;
   if((fp=fopen(argv[1],"w"))==NULL){
	printf("can't open file!\n");
	exit(1);
    }
   if(strcmp(xx[0],"this document has protected by site120\n")==0)
	{
		strcpy(xx[0],"this document has protected by site120 \n");
		for(i=0;i<total;i++)
			fputs(xx[i],fp);
		fclose(fp);
		puts("the first jiemi successful!");
		}
  else if(strcmp(xx[0],"this document has protected by site120 \n")==0)
	{
		for(i=1;i<total;i++)
			for(j=0;j<strlen(xx[i]);j++)
				{xx[i][j]=xx[i][j]-1;}
		for(i=1;i<total;i++)
			fputs(xx[i],fp);
		fclose(fp);
		puts("the second jiemi successful!");
		}
  else{
	 for(i=0;i<total;i++)		/*jiami-------------->>-start */
	for(j=0;j<strlen(xx[i]);j++)
		{
			xx[i][j]=xx[i][j]+1;
		}

   fputs("this document has protected by site120\n",fp); /*output*/
   for(i=0;i<total;i++)
	fputs(xx[i],fp);
  fclose(fp);
	puts("the first jiami successful!");	}	/*jiami--------------->>-end */


}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?