my code is nor working..kindly help
2 views (last 30 days)
Show older comments
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 Comment
Jan
on 22 Oct 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.
Answers (1)
Jan
on 22 Oct 2016
Edited: Jan
on 22 Oct 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.
0 Comments
See Also
Categories
Find more on Encryption / Cryptography 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!