0

I am making simple steganography hiding each one bit in each end of one byte and finding.

fstream file; // readfile
file.open(image.bmp, ios::out | ios::in | ios::binary)
stego.seekg(first_location, ios::beg);
 string cryptogram = "";
int i = 0;
char letter = 0;
char colorBit[8];
int temp;
while (!stego.eof()) {
    stego.read(colorBit, 8); //read 8byte
    loc += 8;
    stego.seekg(loc, ios::beg);
    for (int i = 7; i >=0; i--) { 
//get last bit for each byte those become letter
       temp =  colorBit[i] & 1;
        letter = letter << 1;
        letter = letter | temp;
    }
    //cryptogram += letter;
     cout << letter;
    if (letter == 13) { // if letter is enter stop
       cout << stego.tellg() << endl;
         break;
     }
     letter = 0;
}
  cout << cryptogram << endl;
 stego.close();

but in the middle of process there is error. like If program read 5000 offset and get one char, after that it'll have to go 5008 offset but go -1 offset so i made while loop to fix, like below

while(file.tellg() != expected_offset){
 file.seekg(expected_offset, ios::beg);
}

but it didn't work. so i used clear(), sync() functions and it worked finally. the point is when i made same program in mac os there is no problem and in window if i insert short string (maybe 300~400 letters) no problem too. but if length bigger, error coms up.

i cant get it why.

evergreen
  • 407
  • 4
  • 15
  • 2
    If you are accessing a variable in multiple threads, and at least one of those threads is a writer, you **must** have some sort of synchronization, like a mutex, to protect that variable. – NathanOliver Mar 19 '21 at 12:38
  • 2
    Could you please clarify your problem? What do you want to achieve (in more details, with some example)? What is exactly going wrong? Can you give a [mcve]? – JHBonarius Mar 19 '21 at 12:40
  • seekg does not have errors. Something is wrong with your program. – user253751 Mar 19 '21 at 13:00
  • Temporarily disable the installed anti-malware product and try again. – Hans Passant Mar 19 '21 at 13:24
  • i added more detail code if you see this please check one more time – evergreen Mar 20 '21 at 08:06
  • You want to read [this](https://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-i-e-while-stream-eof-cons). – n. 'pronouns' m. Mar 20 '21 at 08:13

0 Answers0