Caesar cryptic function problem.

I've written a code but im getting some error which Im not able to find out. Help me, please.
function coded = caesar(c,n)
X=c+n;
for ii=1:length(X)
if X(ii) > 126
X(ii)=X(ii)-95;
coded = char(X);
elseif X(ii) < 32
X(ii)= 95+ X(ii);
coded= char(X);
else
coded = char(X);
end
end

1 件のコメント

Jyotsna Talluri
Jyotsna Talluri 2020 年 5 月 18 日
What are your inputs c and n?

サインインしてコメントする。

回答 (1 件)

David Hill
David Hill 2020 年 5 月 18 日

0 投票

Assuming c is a double array
function coded = caesar(c,n)
coded=char(mod(c-32+n,95)+32);
end

カテゴリ

ヘルプ センター および File ExchangeElectrical Block Libraries についてさらに検索

質問済み:

2020 年 5 月 15 日

回答済み:

2020 年 5 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by