my code is nor working..kindly help

조회 수: 2 (최근 30일)
Nazi khan
Nazi khan 2016년 10월 22일
편집: Jan 2016년 10월 22일
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
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
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.

카테고리

Help CenterFile Exchange에서 Encryption / Cryptography에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by