not enough input arguments
Mostrar comentarios más antiguos
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 comentarios
Star Strider
el 29 de Abr. de 2017
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
el 29 de Abr. de 2017
Editada: nurul esniah kamaruddin
el 29 de Abr. de 2017
Star Strider
el 29 de Abr. de 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
el 29 de Abr. de 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?
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 29 de Abr. de 2017
0 votos
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 comentarios
nurul esniah kamaruddin
el 29 de Abr. de 2017
Image Analyst
el 29 de Abr. de 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.
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!