Index error during encryption

im encrypting a message in an image and im having trouble getting the message to go through the cypher. i get an error at line 8 that says "Index exceeds the number of array elements (22)." and cant figure out how to fix it.
l = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',' '];
n = 1:27;
m = 'this is a test message';
d = 1;
em = zeros(1,length(m));
for i = 1:length(m)
for ele = 1:length(l)
if m(d)==l(ele)
em(d)=n(ele);
d=d+1;
end
end

댓글 수: 1

Adam
Adam 2019년 11월 12일
Tick the 'Pause on errors' option in the run menu then just look at d in the workspace or command window when it stops. Apparently it is > 22.

답변 (1개)

Stijn Haenen
Stijn Haenen 2019년 11월 12일

0 개 추천

You can use this script:
l = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',' '];
n = 1:27;
m = 'this is a test message';
d = 1;
em = zeros(1,length(m));
for i = 1:length(m)
em(i)=find(l==m(i));
end

이 질문은 마감되었습니다.

질문:

2019년 11월 12일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by