I am creating a very basic encryption program using XOR to encrypt a user file and decrypt it again. What’s happening however is when I encrypt I get a long line of the same 6 letters and when I try to decrypt it doesn’t work. Can anyone spot the problem? Also, I will want to replace the XOR with a basic encryption method of my own but retain the same code except for the key. Will this be possible? Thanks!
#include <stdio.h>
int main(int argc, char*argv[])
{
FILE *fp1, *fp2;
char* key;
int c;
key = argv[1];
if(*key != '\0')
{
fp1 = fopen(argv[2],"rb");
if(fp1 != NULL)
{
fp2 = fopen(argv[3],"wb");
if (fp2 != NULL)
{
while((c=getc(fp1)!=EOF))
{
if(!*key)key = argv[1];
c ^=*(key++);
putc(c, fp2);
}
fclose(fp2);
}
fclose(fp1);
}
}
return 1;
}
Check your parenthesis: the while should be