Current location - Quotes Website - Personality signature - C language encryption and decryption
C language encryption and decryption

#include

#include

main()

{

char password[10],len,i=0,ch,c;

char infile[20];

FILE * in;

printf( "FILE NAME:");

scanf("%s",infile);

if((in=fopen(infile,"r+"))==NULL)< /p>

{

printf("ERROR!");

exit(0);

}

printf ("KEY:");

scanf("%s",password);

len=0;

while(password[len]!= 0)len++;

while((ch=fgetc(in))!=EOF)

{

c=ch^password[i];< /p>

fseek(in,-1,SEEK_CUR);

fputc(c,in);

fseek(in,ftell(in),SEEK_SET);< /p>

i++;

if(i==len)i=0;

}

fclose(in);

printf("\nNow open the TEXT.\n",infile);

}