not enough input arguments

5 views (last 30 days)
how to fix the problem?
function [varargout] = DES(input64,mode,key)
error(nargchk(1,3,nargin));
switch nargin
case 1
mode = 'ENC';
K = round(rand(8,7));
K(:,8) = mod(sum(K,2),2); % note these eight bits of key are never used in encryption
K = reshape(K',1,64);
varargout{2} = K;
case 2
switch mode
case 'ENC'
K = round(rand(8,7));
K(:,8) = mod(sum(K,2),2); % note these eight bits of key are never used in encryption
K = reshape(K',1,64);
varargout{2} = K;
case 'DEC'
error('Key has to be provided in decryption mode (DEC)')
otherwise
error('WRONG working mode!!! Select either encrtyption mode: ENC or decryption mode: DEC !!!')
end
case 3
if isempty(setdiff(unique(key),[0,1])) % check provided key type
if numel(key) == 64 % check provided key parity
keyParityCheck = @(k) (sum(mod(sum(reshape(k,8,8)),2))==0);
if keyParityCheck(key) == 1
K = key(:)';
else
error('Key parity check FAILED!!!')
end
elseif numel(key) == 56 % add parity bits
K = reshape(key,7,8)';
K(:,8) = mod(sum(K,2),2); % note these eight bits of key are never used in encryption
K = reshape(K',1,64);
varargout{2} = K;
display('Key parity bits added')
else
error('Key has to be either 56 or 64-bit long!!!')
end
else
error('Key has to be binary!!!')
end
  4 Comments
Star Strider
Star Strider on 29 Apr 2017
Please see my previous Comment.
I can help you fix the error if I am certain what it is and where it occurs in your code. I need the complete red error message from your Command Window first.
Walter Roberson
Walter Roberson on 29 Apr 2017
You have posted code for a function, but you have not told us how you are invoking the function. How are you telling MATLAB that you want to execute the function?

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 29 Apr 2017
The error you posted:
Error in DES (line 46)
if numel(input64) == 64 && isempty(setdiff(unique(input64),[0,1]))
means that you are not passing the ‘input64’ argument to the ‘DES’ function. This may mean that you are not passing any other arguments to it either.
You need to create a script with the arguments defined in your code before you call ‘DES’. You cannot call it correctly by clicking on the green triangle in the Editor.
Try something like this in your script file that calls the ‘DES’ function:
input64 = ; % Provide Appropriate Value
mode = ; % Provide Appropriate Value
key = ; % Provide Appropriate Value
ReturnedOutput = DES(input64,mode,key);

More Answers (1)

Image Analyst
Image Analyst on 29 Apr 2017
The answer to fixing virtually all coding problems can be found here
What are you passing in for input64,mode,key? You're not just passing in nothing and simply hitting the green run triangle (or hitting F5) are you? You need to pass in exactly 3 arguments because that's what the function was written to require. What are your 3 values?
  2 Comments
nurul esniah kamaruddin
nurul esniah kamaruddin on 29 Apr 2017
(1,3,nargin), i have seen the examples on another discussion that tell to input these 3 values. it works using matlab2012, but also has error from another line of the code. and when i am trying to use matlab2015 it does not work.
Image Analyst
Image Analyst on 29 Apr 2017
Your comments above to Star do not help. What he and I both asked in in my question. How did you run it, and did you pass anything in for the arguments?
Saying " it works using matlab2012, but also has error from another line of the code" is a contradiction. If it works in R2012 there will be no error message.

Sign in to comment.

Categories

Find more on Characters and Strings in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!