upper case need help

3 vues (au cours des 30 derniers jours)
Maria
Maria le 26 Mai 2020
Commenté : Image Analyst le 26 Mai 2020
function unscramble=latinCipher(scramble)
[str,shift]=strtok(scramble,' ');
shift=str2num(shift);
str=char(mod(double(str)-97+shift,26)+97);
unscramble=upper(str);
end
for my this code, if I put lowercase 'sknz 4' it will output as 'WORD'. How could be fixed by puting uppercase 'SKNZ 4' would output as 'WORD". Because for now if I input 'SKNZ 4' it showed an unexpected value.

Réponse acceptée

Walter Roberson
Walter Roberson le 26 Mai 2020
str=char(mod(double(lower(str))-97+shift,26)+97);
  3 commentaires
Walter Roberson
Walter Roberson le 26 Mai 2020
Your input might be either upper case or lower case, and you want the two to be treated the same way, and the rest of your code assumes it was lower case. That makes the easiest approach to just use lower() to convert uppercase to lowercase (leaving lowercase alone.)
Image Analyst
Image Analyst le 26 Mai 2020
Please "Accept this answer" to give Walter reputation points to thank him.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by