Here's the code for an XOR encryption program I wrote back as a sophomore in high school. It's not great, but it works for both encryption and decryption. After you encrypt the file with it, just re-run the file through the encryption program and it should get back to normal. It's been a while (going on 7 years now) since I wrote it, but I'm pretty sure it still works (I don't have a compiler handy at the moment to test it). If you need anything explained, let me know and I'll do my best.Quote:
Yea, I had messed with XOR not too long ago, but couldn't get the *de*cryption part to work
AJCode:#include <stdio.h>
#define PROG_NAME "encrypt"
void usage()
{
printf("-------------------------------\n");
printf("Invalid command line.\n");
printf("Usage:\n\t%s infile outfile key\n", PROG_NAME);
printf("-------------------------------\n");
}
int main(int argc, char *argv[])
{
int count,bytes;
FILE *in,*out;
if(argc < 4)
{
usage();
return 0;
}
if ((in = fopen(argv[1], "rb")) == NULL)
printf("Error opening %s.\n", argv[1]);
if ((out = fopen(argv[2], "wb")) == NULL)
printf("Error opening %s.\n", argv[2]);
while((count = getc(in)) != EOF)
{
count = (count ^ *argv[3])*(count*count ^ *argv[3]);
bytes++;
putc(count, out);
}
fclose(in);
fclose(out);
printf("Encryption Success:\n");
printf("\tEncrypted %s and stored data in %s.\n", argv[1],argv[2]);
printf("\tWrote %d bytes to %s.\n", bytes,argv[2]);
return 0;
}
