以二进制形式加密字符串并嵌入图像matlab中的问题
我正在研究一个将字符串加密并嵌入图像中的项目,通过使其制作二进制文件。 当我使用 rand()函数生成随机数据时,我的程序完全有效,但是当我尝试真实字符串时,它是不起作用的,我知道它不起作用的是通过在之前和之后比较数据加密,嵌入和解密,提取。 我用来生成随机数据的代码如下:
%% generate binary secret data
num = 1000;
rand('seed',0); % set the seed
D = round(rand(1,num)*1); % Generate stable random numbers
我用于加密的代码是
num_D = length(D); % Find the length of the data D
Encrypt_D = D; % build a container that stores encrypted secrets
%% Generate a random 0/1 sequence of the same length as D based on the key
rand('seed',Data_key); % set the seed
E = round(rand(1,num_D)*1); % Randomly generate a 0/1 sequence of length num_D
%% XOR encryption of the original secret information D according to E
for i=1:num_D
Encrypt_D(i) = bitxor(D(i),E(i));
end
我用来替换随机生成的数据(上面的第一个代码)的代码
D = uint8('Hello, this is the data I want to encrypt and embed rather than randomly generated data');
D = de2bi(D,8);
D = reshape(D,[1, size(D,1)*8]);
,但这是不起作用的,我想知道为什么,为什么,谁能帮我吗?
I was working on a project that encrypts a string and embeds it in the image, how I do is by making it binary.
My program fully worked when I generated random data using the rand() function, but when I try real string, it is not working, how I know it isn't working is by comparing data before and after encrypting, embedding, and decrypting, extract.
The code I used to generate random data is as follows
%% generate binary secret data
num = 1000;
rand('seed',0); % set the seed
D = round(rand(1,num)*1); % Generate stable random numbers
The code I used for encryption is
num_D = length(D); % Find the length of the data D
Encrypt_D = D; % build a container that stores encrypted secrets
%% Generate a random 0/1 sequence of the same length as D based on the key
rand('seed',Data_key); % set the seed
E = round(rand(1,num_D)*1); % Randomly generate a 0/1 sequence of length num_D
%% XOR encryption of the original secret information D according to E
for i=1:num_D
Encrypt_D(i) = bitxor(D(i),E(i));
end
The code I used to replace randomly generated data(The first code above)
D = uint8('Hello, this is the data I want to encrypt and embed rather than randomly generated data');
D = de2bi(D,8);
D = reshape(D,[1, size(D,1)*8]);
But this is not working, I wonder why, can anyone help me with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要使用Bitxor进行加密和解密字符串,您可以做类似的事情:
最后一行执行以下操作:
To encrypt and decrypt a string using bitxor you can do something similar to:
The last line do the following things: