error in decryption code saying not enough input arguments

the code is for decrypting a text from an encrypted image .
clc;
close all;
clear all;
img=imread('enc2.gif');
imshow('enc2.gif');
img1=imread('C:\Users\Anushree Bhatt\Desktop\cd1\Major\desert1.jpg');
img1=img1(:,:,3);
[p,q,r]=size(img);
for i=1:q
disp(img(1,1));
disp(img1(1,1));
disp(img(1,i)-img1(1,i));
if (img(1,i)-img1(1,i)==0)
break;
end
text(i)=(img(1,i)-img1(1,i)+96);
end
len=size(text);
k=len(1,2);
text1=zeros(1,k);
for i=1:k
m=text(i)
for j=1:7
if (j-1)>0
a(j-1)=rem(m,2);
else
a(7)=rem(m,2);
end
m=floor(m/2);
disp(m);
if m==1
a(m)=1;
break;
end
end
for j=0:6
text1(i)=text1(i)+a(j+1)*(2^j);
end
end
text1=char(text1);
disp (text1);
X=('The encrypted text is');
disp(X);
disp(text1);
the error is at m=text(i) saying not enough input arguments.i shall post the code for encryption if required.

 Akzeptierte Antwort

Do not name a variable "text" as that conflicts with the MATLAB graphic function text()
Your code looks through row 1 of the two images, looking for the first column at which the two have the same value. If it happens that the very first location is the same, then your code will never execute the assignment you have currently coded as
text(i)=(img(1,i)-img1(1,i)+96);
and since you do not initialize that variable, the variable would not exist when you go to use it inside the next "for" loop.
You also need to take into account that your imread() is likely returning uint8 values, and that if you subtract a larger uint8 value from a smaller then the result you get is 0, not negative.
disp(uint8(3) - uint8(7)); %is going to give you 0
disp(uint8(7) - uint8(3)); %is going to give you 4
disp(uint8(3) - uint8(7) + 1); %is going to give you 1, because the subtraction gives 0 and you add 1 to that
disp(double(uint8(3)) - double(uint8(7))); %is going to give you -4

9 Kommentare

Can you help me fix this , how can I change the code in order to fix the problem ? Should I subtract img1 from img ?
Change
img=imread('enc2.gif');
to
img = double(imread('enc2.gif'));
and likewise when you read in the other image. That will eliminate the problem with subtraction clipping at 0.
And before your "for i" loop, use
text = [];
in order to initialize "text". Then if you "break" before assigning a value into the variable, it will still exist and size() of it will be [0 0]
now there is no error but the code is not showing the encrypted text .can i post the code of encryption here , you could refer
i have followed the decryption algorithm just in reverse of the encryption algorithm,it is still not returning the encrypted string.
clc;
close all;
clear all;
img=imread('C:\Users\Anushree Bhatt\Desktop\cd1\Major\desert1.jpg');
figure,imshow(img),title('Original Image');
[a,b,c]=size(img);
img3=img(:,:,3);
str=input('Enter a string: ', 's');
str=double(str);
len=size(str);
k=len(1,2);
str1=zeros(1,k);
for i=1:k
m=str(i);
for j=1:7
a(j+1)=rem(m,2);
m=floor(m/2);
%disp(m);
if m==1
a(m)=1;
break;
end
end
for j=0:6
str1(i)=str1(i)+a(j+1)*(2^j);
end
end
disp(str1);
for i=1:size(str1,2)
str1(i)=str1(i)-96;
end
text=zeros(1,size(str1,2)+1);
text=str1;
text(size(str1,2)+1)=0;
for i=1:size(str1,2)+1
img3(1,i)=img3(1,i)+text(i);
end
imwrite(img3,'enc2.gif');
figure,imshow(img3),title('Encrypted Image');
this is the code for encryption.
now its showing a wrong encrypted text, i entered the string 'WELCOME' and on decryption it is showing 'GEEEGEE'
Have you looked at dec2bin() or de2bin() and their reverse functions? or bitset() and bitget() ? They might be a bit more robust than your current code.
Anushree Bhatt
Anushree Bhatt am 6 Mai 2015
Bearbeitet: Anushree Bhatt am 6 Mai 2015
Yes , that is not the problem , the problem seems to be at rotating the binary number of ascii code by one digit
thank you for the help , my code worked . :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Entering Commands finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by