I have basic code that looks like this:
while(inputfileStream.good())
{
for(int i = 0;i<levels;i++)
{
inputfileStream.open(_file,ios::in | ios::out | ios::binary);
for(int i = 0,kPOS=0;i<=fsize;i++,kPOS++)
{
if(kPOS > Ksize)
kPOS=0;
char tempchar = 0;
inputfileStream.seekg(i,ios::beg);
inputfileStream.get(tempchar);
tempchar+=(int)_encription_key[kPOS];
inputfileStream.seekg(i,ios::beg);
inputfileStream.put(tempchar);
}
inputfileStream.close();
}
}
It’s a basic encrypter. I just have one problem: For each level of encryption I have to reopen the file to get its contents. Otherwise if I do not do this I have the same old text when I decrypt the file from each level.
Could you help me out and give a more efficent way of rereading the files contents besides calling open() and close()?
Instead of closing and opening the file, you can
This may be clearer to you if you set exceptions() on your fstream. You are most likely not seeing your encryption working at some points due to the fstream not being in the good() state.