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!