this is apart from a code for image encryption using chaotic map, please help me to know what is the wrong with this code
Afficher commentaires plus anciens
x(1)=0.2350;
y(1)=0.3500;
z(1)=0.7350;
a(1)=0.0125;
b(1)=0.0157;
l(1)=3.7700;
image_height=256;
for i=1:1:70000
x(i+1)=l*x(i)*(1-x(i))+b*y(i)*y(i)*x(i)+a*z(i)*z(i)*z(i);
y(i+1)=l*y(i)*(1-y(i))+b*z(i)*z(i)*y(i)+a*x(i)*x(i)*x(i);
z(i+1)=l*z(i)*(1-z(i))+b*x(i)*x(i)*z(i)+a*y(i)*y(i);
end
x=ceil(mod((x*100000),image_height));
y=ceil(mod((y*100000),image_height));
z=ceil(mod((z*100000),image_height));
original=imread('peppers.png');
rgb=rgb2gray(original);
[row,col]=size(rgb);
n=500;
p=600;
q=700;
for j=1:1:row
k(j)=x(j+n);
l(j)=y(j+p);
end
% for i=1:1:row
% k(i)=x(i+n);
% end
% for j=1:1:col
% l(j)=y(j+p);
% end
for j=1:1:col*row
m(j)=z(j+q);
end
please i want to know what's the error in the last command line " m(j)=z(j+q);"
when i run i got error in this line , please help me
7 commentaires
DGM
le 3 Mai 2021
>> size(z)
ans =
1 70001
>> [row col q]
ans =
384 512 700
>> row*col+q
ans =
197308
>> 197308>70001
ans =
logical
1
Samaa Yasser
le 3 Mai 2021
Rik
le 3 Mai 2021
Because you thoroughly explained what each line is doing, it is easy to suggest an edit. Oh, wait.
We have no clue why you expect j+q to be small enough to index z.
You are also dynamically growing arrays, even when you can predict the size in advance. That almost always reduces performance and clarity.
Rik
le 3 Mai 2021
If this is your own code, why did you ignore the advice you previously received?
And if this isn't your own code: where did you get this and have you asked the original author for clarification?
DGM
le 4 Mai 2021
I have no idea what it should be. What is the conceptual relationship between 100000, 70001, 500, 600, 700, and the size of any arbitrary image you load? I suspect that the answer is that there isn't one.
P.S. I like how the image is called 'rgb' the moment it's not actually RGB anymore. By the same token, single-letter variable names aren't descriptive. Nobody else knows what your code means if you don't communicate it.
Rik
le 4 Mai 2021
@DGM That is actually what allows this discussion. If this code wasn't fundamentally broken it would be a question about implementing cryptography, which is classified as a weapon in US law (yes, seriously). Discussing it on a website that can be reached from outside of the US is considered as a weapons export, which requires permission being granted prior to publishing.
It is a stupid system that makes no sense in this case, but since the Mathworks website is governed by US law, in general discussions about cryptography aren't allowed. (although there is hardly any enforcement of this rule, for more context, see this thread)
DGM
le 4 Mai 2021
Yeah, I figured I wouldn't bring it up. The ridiculousness of reality needs no aid to stay in memory.
Réponses (0)
Catégories
En savoir plus sur Encryption / Cryptography dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!