开发者

Reading bmp file for steganography

开发者 https://www.devze.com 2022-12-23 11:54 出处:网络
I am trying to read a bmp file in C++(Turbo). But i m not able to print binary stream. I want to encode txt file into it and decrypt it.

I am trying to read a bmp file in C++(Turbo). But i m not able to print binary stream.

I want to encode txt file into it and decrypt it. How can i do this. I read that bmp file header is of 54 byte. But how and where should i append txt file in bmp file. ?

I know only Turbo C++, so it would be helpfull for me if u provide solution or suggestion related to topic for the same.

int main()
{
ifstream fr; //reads
ofstream fw; // wrrites to file
char c;
int random;
clrscr();
char file[2][100]={"s.bmp","s.txt开发者_StackOverflow"};

fr.open(file[0],ios::binary);//file name, mode of open, here input mode i.e. read only
if(!fr)
    cout<<"File can not be opened.";
fw.open(file[1],ios::app);//file will be appended
if(!fw)
    cout<<"File can not be opened";
while(!fr)
    cout<<fr.get(); // error should be here. but not able to find out what error is it

fr.close();
fw.close();
getch();
}

This code is running fine when i pass txt file in binary mode

EDIT :

while(!fr)
    cout<<fr.get(); 

I am not able to see binary data in console this was working fine for text when i was passing character parameter in fr.get(c)


I think you question is allready answered: Print an int in binary representation using C

convert your char to an int and you are done (at least for the output part)


With steganography, what little I know about it, you're not "appending" text. You're making subtle changes to the pixels (shading, etc..) to hide something that's not visually obvious, but should be able to be reverse-decrypted by examining the pixels. Should not have anything to do with the header. So anyway, the point of my otherwise non-helpful answer is to encourage you go to and learn about the topic which you seek answers, so that you can design your solution, and THEN come and ask for specifics about implementation.


You need to modify the bit pattern, not append any text to the file. One simple example : Read the Bitmap Content (after header), and sacrifice a bit from each of the byte to hold your content


If on Windows, recode to use CreateFile and see what the real error is. If on Linux, ditto for open(2). Once you have debugged the problem you can probably shift back to iostreams.

0

精彩评论

暂无评论...
验证码 换一张
取 消