logic problem with circshift
1 view (last 30 days)
Show older comments
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149362/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149364/image.jpeg)
we are trying to unscramble a scrambled picture using circshift command with the help of a key image. but we cant recover the original picture. plz plz plz check our code T.T ASAP!! scrambler
clc;
clear all;
close all;
I=imread('lenna1.jpg');
I1=(I);
imshow(I1);
drawnow
pause
i=I1(:,:,1);
i1=I1(:,:,1);
l=size(i,1);
h=size(i,2);
name=0;
naam=1;
key=imread('key.jpg');
keyr=key(:,:,1);
s1=sum(keyr,1);
for k=1:h
if (mod((s1(k)),2)==0)
i(k,:)=circshift(i(k,:),[0 20]);
elseif (mod((s1(k)),3)==0)
i(k,:)=circshift(i(k,:),[0 -30]);
elseif (mod((s1(k)),5)==0)
i(k,:)=circshift(i(k,:),[0 50]);
elseif (mod((s1(k)),7)==0)
i(k,:)=circshift(i(k,:),[0 -70]);
elseif (mod((s1(k)),11)==0)
i(k,:)=circshift(i(k,:),[0 110]);
elseif (mod((s1(k)),13)==0)
i(k,:)=circshift(i(k,:),[0 -130]);
else
i(k,:)=circshift(i(k,:),[0 -20]);
end
naam
end
ir=i;
J1=I1;
J1(:,:,1)=ir;
J=(J1);
imshow(J(:,:,1));
imwrite(J,'scrlenna.jpg');
unscrambler
clc
clear all
close all
I=imread('scrlenna.jpg');
i=I(:,:,1);
l=size(i,1);
h=size(i,2);
J=I;
key=imread('key.jpg');
keyr=key(:,:,1);
s=sum(keyr,2);
s1=sum(keyr,1);
for k=1:h
if (mod((s1(k)),2)==0)
i(k,:)=circshift(i(k,:),[0 -20]);
elseif (mod((s1(k)),3)==0)
i(k,:)=circshift(i(k,:),[0 30]);
elseif (mod((s1(k)),5)==0)
i(k,:)=circshift(i(k,:),[0 -50]);
elseif (mod((s1(k)),7)==0)
i(k,:)=circshift(i(k,:),[0 70]);
elseif (mod((s1(k)),11)==0)
i(k,:)=circshift(i(k,:),[0 -110]);
elseif (mod((s1(k)),13)==0)
i(k,:)=circshift(i(k,:),[0 130]);
else
i(k,:)=circshift(i(k,:),[0 20]);
end
end
J(:,:,1)=i;
imwrite(J,'yahooo.jpg');
imshow(J);
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!