Vigenère cipher: Difference between revisions
Content added Content deleted
(Improved D code, removed undefined code (See C codepoints)) |
|||
Line 316:
=={{header|D}}==
{{trans|C++}}
ASCII only:
<lang d>import std.stdio, std.string, std.ctype;
string encrypt(string text, in string key) {
string res;
int j;
foreach (c; text.toupper) {
if (!isupper(c
j++;
j %= key.length;
}
return res;
}
string decrypt(string text, in string key) {
string res;
int j;
foreach (c; text.toupper) {
if (!isupper(c
j++;
j %= key.length;
}
return res;
}
void main() {
auto key = "VIGENERECIPHER";
auto ori = "Beware the Jabberwock, my son!"
" The jaws that bite, the claws that catch!";
auto enc = encrypt(ori, key);
writeln(enc);
|