Need to utilise only letter ASCII in Caesar Cipher Code
3 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I am currently creating a Caesar cipher code and need help, please:
- A caesar code reverses letter order and capitalisation.
I have written a short code below, which performs the shift correctly, however, I am unsure how to reverse capitalisation, and only edit the letters.
function [out_str] = str_edit(in_str, shift)
char_set = char(32):char(126);
[out_str] = char(in_str+shift);
end
0 件のコメント
回答 (1 件)
Walter Roberson
2022 年 9 月 11 日
Hint:
T('A':'Z') = circshift('a':'z', count)
encoded = T(msg)
2 件のコメント
Walter Roberson
2022 年 9 月 13 日
Example:
T = char(1):char(255);
T('A':'C') = 'bca';
T('a':'c') = 'BCA';
msg = 'Call a cab!'
T(msg)
What was uppercase A to C become lower-case and also shifted by 1. What was lowercase a to c become upper-case and also shifted by 1. Things outside of A B C a b c are not affected.
If you calculate the replacement vector based upon your shift count, then the indexing of T with the msg does all of the case changing and shifting at the same time, without any need of a for loop.
参考
カテゴリ
Help Center および File Exchange で Encryption / Cryptography についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!