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.