读取 bmp 文件进行隐写术
我正在尝试用 C++(Turbo) 读取 bmp 文件。但我无法打印二进制流。
我想将txt文件编码到其中并解密。 我怎样才能做到这一点。我读到 bmp 文件头是 54 字节。但是我应该如何以及在何处将 txt 文件附加到 bmp 文件中。 ?
我只知道 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();
}
当我以二进制模式传递txt文件时,此代码运行正常
编辑:
while(!fr)
cout<<fr.get();
我无法在控制台中看到二进制数据 当我在 fr.get(c) 中传递字符参数时,这对于文本工作正常
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"};
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我想你的问题已经得到解答:
使用 C 以二进制表示形式打印 int
将 char 转换为一个 int 就完成了(至少对于输出部分)
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
如果在 Windows 上,重新编码以使用 CreateFile 并查看真正的错误是什么。如果在 Linux 上,则与 open(2) 相同。调试完问题后,您可能可以转回 iostream。
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.