Code debugging help needed

4 views (last 30 days)
fiona rozario
fiona rozario on 3 Jun 2017
Answered: John D'Errico on 3 Jun 2017
I have the following code:
clc;
close all;
clear;
workspace;
N=3;
% Select file
for i=1:N
filename=uigetfile('*.*','Select first encrypted image file');
f{i,1}=imread(filename);
end
%Separate RGB
for i=1:N
red{i,1}=uint8(f{i}(:,:,1));
green{i,1}=uint8(f{i}(:,:,2));
blue{i,1}=uint8(f{i}(:,:,3));
end
%Decrypt and deshuffle each component
for i=1:N
red{i}=moddeshuffleshare(red{i});
green{i}=moddeshuffleshare(green{i});
blue{i}=moddeshuffleshare(blue{i});
dred{i}=decrypt_modulus(red{i});
dgreen{i}=decrypt_modulus(green{i});
dblue{i}=decrypt_modulus(blue{i});
end
'moddeshuffleshare' and 'decrypt_modulus' are functions. 'decrypt_modulus' has a step where gcd is calculated.
I am getting the following error:
Error using gcd (line 49)
Double input is out of integer type range.
Error in decrypt_modulus (line 15)
g=gcd(share(i,j),m);
Error in nsharestest (line 39)
dred{i}=decrypt_modulus(red{i});
But I checked the 'red' variable and it is not a double. It is uint8. Where am I going wrong? Is my method of reading in the files correct since all files are pngs?

Answers (1)

John D'Errico
John D'Errico on 3 Jun 2017
READ THE EROR MESSAGE. This is important, since the error message tells you whatit thinks is wrong.
Where does it say the error came from?
Error using gcd (line 49)
Double input is out of integer type range.
Error in decrypt_modulus (line 15)
g=gcd(share(i,j),m);
Error in nsharestest (line 39)
dred{i}=decrypt_modulus(red{i});
Starting at the top, it tells you the error came from GCD. GCD is not happy with something. The problem happened inside decrypt_modulus. But the error was in the call:
g=gcd(share(i,j),m);
Are both of those values the proper class?
The point is, red{i} is NOT the issue, at least not directly.
Learn to use the error messages. Read them.
Next, you will find it useful to learn to use the debugger.
help dbstop
A nice trick is to turn the debugger into a mode where it will stop as soon as it sees an error. Then you can check to see what caused the error. Use this call to set the debugger in operation.
dbstop if error

Categories

Find more on Programming Utilities in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!