encryption - 如何在图像中封装一些文本信息并使用 MATLAB 将其提取出来?

标签 encryption matlab steganography

new_img = convert(img, text);
(img, text) = convert_back(new_img);

有人可以用 MATALB 的内置图像来说明吗?

最佳答案

我相信您正在寻找 steganography .您可以从 LSB steganography 的这个 MATLAB 实现开始.

进行 LSB 隐写术的一种简单方法是采用无损压缩图像并设置每个分量 (R,G,B) 的 LSB。然后对于 m x n 图像,您将获得 3mn 位来存储信息。由于您正在修改 LSB,因此差异不会在图像中可感知。

更新

所以我决定编写一个小的、低效但示范性的例子:

function LSBStega    
        %%// Image and text
        I = imread('coins.png');
        text = 'Hello World etc';
        assert(numel(I) > numel(text)*8,'Insufficient number of pixels');

        %%// Encode
        %// The end character signifies the end of the hidden text
        end_char = '.';
        %// Append it
        text = [text end_char];
        %// Convert each character into binary form with atleast 8 bits
        %// We transpose it before calling (:) since the binary representation
        %// is stores each character in binary per row and the (:) operations
        %// vectorizes the matrix by column.
        b = transpose(dec2bin(text,8));
        %// Find which bits should be set to 1 or 0
        ind_0 = find(b == '0');
        ind_1 = find(b == '1');
        %// Set the appropriate bits to 1 and 0 and leave the rest alone
        I(ind_0) = bitset(I(ind_0),1,0);
        I(ind_1) = bitset(I(ind_1),1,1);

        %%// Faster decode
        text_back = [];        
        for i = 1:8:numel(I)
            %// Extract the LSB from a set of 8 bytes in the image
            C = bitget(I(i:i+7),1);
            %// Convert from binary to decimal
            C = bin2dec(num2str(C));
            %// Check if it's the end character; break if so, store if not
            if(C == end_char) 
                break;
            else
                text_back(end+1) = C;
            end
        end
        %// Convert to text
        text_back = char(text_back);

        %%// Display
        subplot(1,2,1);
        title('Original');
        imshow(imread('coins.png'));
        subplot(1,2,2);
        title('Steganography Result');
        imshow(I);
        disp(text_back);    
end

关于encryption - 如何在图像中封装一些文本信息并使用 MATLAB 将其提取出来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2707023/

相关文章:

javascript - 如何在 node.js 上将文本转换为 Base58?

php - PHP环境加密私钥存放在哪里

encryption - bcrypt,河豚的密码最大长度

Matlab顺序乘法3D矩阵

java - 在java中可逆地改组一个int数组

c - 从缓冲区读取字节(字符)

ruby - 在 .NET 的 Ruby 中使用 3DES 解密十六进制字符串

matlab - 非静态环境中的目标跟踪

matlab - 我是否通过声明全局变量而不是将它们作为参数传递来节省 MATLAB 中的内存?

c# - C# 中 libJPEG 中的 height_in_blocks