Vigenère cipher: Difference between revisions

→‎{{header|D}}: handle multibyte chars
(→‎{{header|D}}: less compact but faster)
(→‎{{header|D}}: handle multibyte chars)
Line 320:
string encrypt(string txt, in string key) {
string res;
foreach (dchar c; txt.toupper) {
if (c < 'A' || c > 'Z') continue;
res ~= (c + key[res.length % $] - 2 * 'A') % 26 + 'A';
Line 329:
string decrypt(string txt, in string key) {
string res;
foreach (dchar c; txt.toupper) {
if (c < 'A' || c > 'Z') continue;
res ~= (c - key[res.length % $] + 26) % 26 + 'A';
Anonymous user