简体   繁体   English

读取bmp文件以进行隐写

[英]Reading bmp file for steganography

I am trying to read a bmp file in C++(Turbo). 我正在尝试在C ++(Turbo)中读取bmp文件。 But im not able to print binary stream. 但即时通讯无法打印二进制流。

I want to encode txt file into it and decrypt it. 我想将txt文件编码并解密。 How can i do this. 我怎样才能做到这一点。 I read that bmp file header is of 54 byte. 我读到bmp文件头是54字节。 But how and where should i append txt file in bmp file. 但是我应该如何以及在哪里将txt文件附加在bmp文件中。 ?

I know only Turbo C++, so it would be helpfull for me if u provide solution or suggestion related to topic for the same. 我只知道Turbo C ++,所以如果您提供与主题相关的解决方案或建议,这对我会有所帮助。

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

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 当我以二进制模式传递txt文件时,此代码运行良好

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) 我无法在控制台中看到二进制数据,当我在fr.get(c)中传递字符参数时,这对于文本来说运行良好

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 一个简单的示例:读取位图内容(在标头之后),并从每个字节中牺牲一点来保存内容

I think you question is allready answered: Print an int in binary representation using C 我认为您的问题已经得到答案: 使用C以二进制表示形式打印int

convert your char to an int and you are done (at least for the output part) 将您的char转换为int即可完成操作(至少对于输出部分而言)

If on Windows, recode to use CreateFile and see what the real error is. 如果在Windows上,请重新编码以使用CreateFile并查看真正的错误是什么。 If on Linux, ditto for open(2). 如果在Linux上,则与open(2)相同。 Once you have debugged the problem you can probably shift back to iostreams. 调试完问题后,您可能可以改回iostream。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM