hello, I'm working on a program to encrypt using Caesar cipher, but the encryption I am receiving one letter only. For example, I input (car) but i receive only the letter (F).
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
clc
clear all;
close all;
p=input('enter plain text: ', 's')
p=lower(p);
lp=size(p);
for i=1:lp
c(i)=int16(p(i))-97+3;
end
c=mod(c,26)+65;
c=char(c)
0 Commenti
Risposte (1)
Voss
il 24 Dic 2022
Modificato: Voss
il 24 Dic 2022
lp is a 1-by-2 vector, only the first element of which is used in a colon expression (as you are using it, in defining your for loop). So if p is a row vector, the size of p is 1-by-something, so lp will be [1 something], and the for loop iterates once.
Instead of using size, use numel.
Consider the difference between this:
p = 'car';
lp = size(p)
for i = 1:lp
disp(['Iteration ' num2str(i)]);
end
And this:
p = 'car';
lp = numel(p)
for i = 1:lp
disp(['Iteration ' num2str(i)]);
end
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!