loop for image encryption gives error
1 回表示 (過去 30 日間)
古いコメントを表示
I am using 8*8 matrix for image encryption but there is an error in loop which i cannot figure out why.
Km=[K11 K12;K21 K22];% 8 cross 8 matrix
I=imread('lena256.jpg');
imshow(I);
[X Y]=size(I);
for i=1:X
for j=1:4:Y
P=double(I(i,j:j+3));
EncImg(i,j:j+3)=mod((Km*P')',256);
end
error is in EncImg(i,j:j+3)=mod((Km*P')',256))
7 件のコメント
Walter Roberson
2019 年 7 月 31 日
Most jpg images are rgb even when they look gray. Real grayscale jpg images are rare. You should always check ndims of a jpg image and rgb2gray if it is not 2.
採用された回答
KALYAN ACHARJYA
2019 年 7 月 31 日
for j=1:4:Y-3
12 件のコメント
KALYAN ACHARJYA
2019 年 8 月 1 日
編集済み: KALYAN ACHARJYA
2019 年 8 月 1 日
You are continously changing the code.
Initialy
P=double(EncImg(i,j:j+7,z));
Now
P=double(I2(i,j:j+7));
Now another term I2, Have you defined I2? Be ensure that all variables or images must be defined before it used.
It would be better, if you provide the complete code, what you have, all inputs required (images also), the code you have tried so far and what result you are expecting.
Walter Roberson
2019 年 8 月 1 日
When you use
[X Y]=size(I);
then that acts like
temp = size(I);
X = temp(1);
Y = prod(temp(2:end));
For RGB files, that results in Y being 3 times the number of columns instead of being the number of columns.
その他の回答 (1 件)
sadiqa ilyas
2019 年 8 月 1 日
4 件のコメント
Walter Roberson
2019 年 8 月 1 日
This is getting close to the point where I have to stop you and say that we cannot help you any further. Due to the laws of the USA, we can effectively only discuss encryption here as long as your program is pretty broken, to the point where someone else would have trouble using the code to implement a working encryption function. When we start getting to the point where there is a chance that your program might start working, we cannot assist you further and we cannot permit you to post code that is nearly working.
The laws of the USA about this might not be wise or convenient, but we have to live with them.
参考
カテゴリ
Help Center および File Exchange で Encryption / Cryptography についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!