void encrypt(void) {
char cryptkey[] = "OkD9dal13lfjf893l*7mf9iLdfm90q";
int i=0;
FILE *ifilep, *ofilep;
char c;
if ((ifilep=fopen("test.zip","rb")) == NULL) {
printf("Couldn''t load input file.");
exit(1);
}
if ((ofilep=fopen("encrypt.dat","wb")) == NULL) {
printf("Couldn''t create output file.");
exit(1);
}
while ((c=getc(ifilep)) != EOF) {
c = c ^ cryptkey[i++];
fputc(c,ofilep);
if (i==30) i=0;
}
fclose(ofilep); fclose(ifilep);
}
Know when I test this on a text file, it works fine. But when I try to do it with a binary it only writes a few bytes to the file, even when the input file is about 50k.
Does anyone know what the problem is?
text ok, binary nope
I''ve got this little function that does a simple encryption with a key. Here it is:
Although I can''t confirm this, I suspect the getc/putc functions are intended for text files. With binary files, I would use fread/fwrite.
---- --- -- -
Blue programmer needs food badly. Blue programmer is about to die!
---- --- -- -
New York. New York. New York. Texas. Texas. New York. New York. Canada.
---- --- -- -
---- --- -- -
Blue programmer needs food badly. Blue programmer is about to die!
---- --- -- -
New York. New York. New York. Texas. Texas. New York. New York. Canada.
---- --- -- -
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement