not enough input arguments
显示 更早的评论
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 个评论
Star Strider
2017-4-29
What is the exact error?
How are you calling your function? Are you calling it from a script, from the Command Window, or are your using the green ‘Run’ arrow in the MATLAB Editor?
Copy all the red error output from your Command Window and paste it in a comment here. We cannot run your code, particularly because we do not know what the inputs should be to your function, so we cannot reproduce the error ourselves.
nurul esniah kamaruddin
2017-4-29
编辑:nurul esniah kamaruddin
2017-4-29
Star Strider
2017-4-29
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
2017-4-29
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?
采纳的回答
更多回答(1 个)
Image Analyst
2017-4-29
0 个投票
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 个评论
nurul esniah kamaruddin
2017-4-29
Image Analyst
2017-4-29
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!