I've wrote a program that takes a text file in as a string, and encrypts it, using my own, very weak, encryption key. The program works, as long as the text file contains only a single word, with no spaces. I'm assuming for some reason it doesn't like spaces. My code is as follows
Code:
#include <stdio.h>
#include <string.h>
int main (int argc, char *argv[])
{
FILE *in;
FILE *out;
char buf[512];
char secret[512];
int x;
in = fopen ( argv[1], "r" );
out = fopen (argv[2], "w+" );
if ( in == NULL ) {
perror ( "Unable to open the file" );
}
/* Read a string */
fread ( buf, 1, sizeof buf, in );
printf ( "%s\n", buf );
/*pre programm processesing and beautifying*/
system("clear");
printf("\n\n");
for (x = 0; x < 512; x++) { //begin for loop
switch(buf[x])
{ //begin switch/case
// encryption key hidden for security reasons
} //end switch/case
} //end for loop
fprintf(out, "%s\n", secret);
fclose ( in );
fclose (out);
printf("%s\n", secret);
printf("\n\n");
} //end main
If anyone could recommend any modifications, I'd appreciate it.
Michael