gpt4 book ai didi

java - 解码 .bmp 图像

转载 作者:行者123 更新时间:2023-12-01 14:39:40 24 4
gpt4 key购买 nike

我刚刚开始学习计算机科学,我们的老师给了我们这个小但棘手的编程作业。我需要解码 .bmp 图像 http://postimg.org/image/vgtcka251/我们的老师交给了我们经过 4 个小时的研究和尝试,我还没有更接近解码它。他给了我们他的编码方法:

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class HideMsgInPicture {
final static long HEADSIZE=120;

public static void main(String[] args) throws IOException {
encode();
decode();
}
private static void encode() throws IOException {
FileInputStream in = null;
FileInputStream msg = null;
FileOutputStream out = null;
try {
in = new FileInputStream("car.bmp");
msg = new FileInputStream("msg.txt");
out = new FileOutputStream("carX.bmp");
int c,mb;
byte clearBit1 = (byte) 0xFE; //254; // 11111110

for (int i=1;i<=HEADSIZE;i++) out.write(in.read()); //copy header

while ((mb = msg.read()) != -1) { // for all byte in message

for (int bit=7; bit>=0; bit--) // 1 bit a time from messsage
{ c = in.read() & clearBit1; // get picturebyte,clear last bit
c = (c | ((mb >> bit) & 1));// put msg-bit in end of pic-byte
out.write(c); // add pic-byte in new file
}
}

for (int bit=7; bit>=0; bit--) // add 8 zeroes as stop-byte of msg
{ c = in.read() & clearBit1; // get picturebyte,clear last bit
out.write(c); // add pic-byte in new file
}

while ((c = in.read()) != -1) out.write(c);// copy rest of file
}
finally {
if (in != null) in.close();
if (msg != null) msg.close();
if (out != null) out.close();
}
}
}

有人能引导我走向正确的方向吗?

最佳答案

您对隐写术了解多少?最简单的算法(即您的作业正在实现的算法)是最低有效位 (LSB)。简而言之,您将消息转换为二进制(即字符“a”= 01100001)并将各个位写入像素值的最右边位。例如,取 8 个像素(每个像素代表一个字节),第一个字节隐藏 0,第二个字节隐藏 1,第三个字节隐藏 1,第四个字节隐藏 0,等等。要提取消息,请从像素中的 LSB 并将其转换回文本。

你的老师给了你隐藏算法,所以基本上你必须编写一个反转该过程的算法。您不需要再看更多,您只需要了解这段代码的作用即可。只需内嵌注释就足够了。

关于java - 解码 .bmp 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16102362/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com