my code is nor working..kindly help
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Jan
2016 年 10 月 22 日
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.
回答 (1 件)
Jan
2016 年 10 月 22 日
編集済み: Jan
2016 年 10 月 22 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Encryption / Cryptography についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!