I'm a newbie, so please be nice to me ;-)
I've been programming in C for about a month now, but I haven't really done alot. I'm trying to write one of those simple XOR encryption programs.
I want to open a text file, read form it charcter by charcter
encrypt each line
write the number to a a file
then
read file line by line
decrypt each line
write decrypted file
I have no problems encrypting the file, it is decrypting thats my problem. I'm using spaces to separate each charcater, and I have no clue how to make the string of numbers into intergers.
I hope thats clear enough... If you have any questions let me know. Thank you!
Here is a piece of the code...
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "encfunc.h"
#include "fexist.h"
void enc_file(void)
{
char buffer[256];
int key = 99;
int count = 0;
int enc = 0;
FILE *in, *out;
if ((in = fopen("in.txt", "r")) == NULL)
{
fprintf(stderr, "Error opening file!");
exit(EXIT_FAILURE);
}
if ((out = fopen("out.txt", "w")) == NULL)
{
fprintf(stderr, "Error opening file!");
exit(EXIT_FAILURE);
}
while (1) {
enc = fgetc(in);
if (!feof(in))
{
enc = enc ^ key;
fprintf(out, "%d ", enc);
}
else
break;
}
fclose(in);
fclose(out);
}
void denc_file(void)
{
char buffer[256];
int key = 99;
int tmp = 0;
int enc = 0;
int len = 0;
FILE *fp;
if ((fp = fopen("test.txt", "r")) == NULL)
{
fprintf(stderr, "Error opening file!");
exit(EXIT_FAILURE);
}
fclose(fp);
}