首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解码.bmp图像

解码.bmp图像
EN

Stack Overflow用户
提问于 2013-04-19 18:17:48
回答 1查看 3.9K关注 0票数 0

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

代码语言:javascript
复制
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();
        }
    }
}

有没有人能把我送到正确的方向?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-20 07:27:28

你对隐写术了解多少?最简单的算法(也就是你的赋值实现的算法)是最低有效位(LSB)。简而言之,您将消息转换为二进制(即字符'a‘= 01100001),并将各个位写入像素值的最右侧位。例如,取8个像素(每个像素由一个字节表示),并在第一个字节中隐藏0,在第二个字节中隐藏1,在第三个字节中隐藏1,在第四个字节中隐藏0,依此类推。要提取消息,请从像素中的LSB获取二进制字符串,并将其转换回文本。

你的老师给了你隐藏算法,所以基本上你必须写一个算法来颠倒这个过程。你不需要看得更远,你只需要理解这段代码是做什么的。仅仅是内联注释就足够了。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16102362

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档