Well, Im trying to write a simple programm for encrypting and decrypting source files(C++,Java), for my programming class. I read one character at a time and use XOR encryption(from the tutorials) and copy that one character to another file. The problem is that it wont copy the entire file, only about a half of it, and im not able to figure it out since i newer really did any FILE I/O at all. Heres a basic idea behind the code:
Code:
//key is a password string
//z is a counter for key
ostream a_file(filename,ios::in);
istream b_file(finename2);
while ( a_file)
{
x=a_file.get();
z++;
if(z>4) z=0;
y=char(x^key[z]);
b_file.put(y);
}
Thats the basic idea behind the code, any help would be apreciated.
PS:
here's the original file:
Code:
#include<iostream.h>
#include<fstream.h>
void main(int argc,char *argv[])
{
cout<<argv[0]<<'\n';
char x;
char y;
char key[5];
int z=0;
char file_a[10];
char file_b[10];
cout<<"Please enter the name of the source file\n";
cin.get(file_a,10);
cin.ignore(80,'\n');
cout<<"Now please enter the name of destination file\n";
cin.get(file_b,10);
cin.ignore(80,'\n');
cout<<"Please enter yor 5 letter key\n";
cin.get(key,5);
cin.ignore(80,'\n');
ifstream a_file(file_a,ios::in);
ofstream b_file(file_b);
while ( a_file)
{
x=a_file.get();
z++;
if(z>4) z=0;
y=char(x^key[z]);
b_file.put(y);
}
cout<<"Operation finished sucessfully!\n";
a_file.close();
b_file.close();
}
after XORing etc., this is what i copies:
Code:
#include<iostream.h>
#include<fstream.h>
void main(int argc,char *argv[])
{
cout<<argv[0]<<'\n';
{
char x;
char y;
char key[5];
int z=0;
char file_a[10];
char file_b[10];
cout<<"Please enter the name of the source file\n";
cin.get(file_a,10);
cin.ignore(80,'\n');
cout<<"Now please enter the name of destination file\n";
cin.get(file_b,10);
cin.ignore(80,'\n');
cout<<"Please enter yor 5 letter key\n";
cin.get(keś›//!!!wtf???