my code is nor working..kindly help

2 visualizzazioni (ultimi 30 giorni)
Nazi khan
Nazi khan il 22 Ott 2016
Modificato: Jan il 22 Ott 2016
function result = shift5(message)
% decodes a message encoded with a Caesar shift
% cipher of 5. Assumes message is all upper
% case letters.
len = length(7);
result = zeros(1,len);
temp = ' ';
for ch = 1:len
temp = message(ch) - 5;
if (temp < 65)
temp = temp + 26;
end
result(ch) = temp;
end
result = char(result);
  1 Commento
Jan
Jan il 22 Ott 2016
I've formatted you code using the "{} code" button. Please care about the readability of your question, when you want others to read it. Thanks.
Please do not only mention, that the code does not work, but provide the information about what fails. Do you get an error message or do the results differ from your expectations? It is easier to solve a problem than to guess what the problem is.

Accedi per commentare.

Risposte (1)

Jan
Jan il 22 Ott 2016
Modificato: Jan il 22 Ott 2016
len = length(7);
Now len is 1: The length of the array [7], which is a scalar.
Most likely you want:
len = length(message)
You can use the debugger to find such bugs: Set a breakpoint in teh first line of the code and step through the function line by line, while you inspect the values of the variables e.g. in the workspace browser.

Categorie

Scopri di più su Encryption / Cryptography in Help Center e File Exchange

Tag

Non è stata ancora inserito alcun tag.

Community Treasure Hunt

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

Start Hunting!

Translated by