Vigenère cipher: Difference between revisions

Modified D version
(Improved D code)
(Modified D version)
Line 315:
 
=={{header|D}}==
{{trans|C++}}
ASCII only:
<lang d>import std.stdio, std.string;
 
string encrypt(in string text, in string key) {
string encoded;
foreach (i, c; text.toupper().removechars("^A-Z"))
Line 325 ⟶ 324:
return encoded;
}
 
string decrypt(in string encoded, in string key) {
string decoded;
foreach (i, c; encoded.toupper().removechars("^A-Z"))
Line 332 ⟶ 331:
return decoded;
}
 
void main() {
auto key = "VIGENERECIPHER";
auto orioriginal = "Beware the Jabberwock, my son!" ~
" The jaws that bite, the claws that catch!";
auto encencoded = encrypt(orioriginal, key);
writeln(encencoded, "\n", decrypt(encencoded, key));
}</lang>
Output:
Anonymous user