Vigenère cipher: Difference between revisions
Content deleted Content added
→{{header|PicoLisp}}: Added PureBasic |
Improved D code |
||
Line 317:
{{trans|C++}}
ASCII only:
<lang d>import std.stdio, std.string
string encrypt(in string text, in string key) {
string
▲ foreach (c; text.toupper) {
▲ res ~= (c + key[j] - 2 * 'A') % 26 + 'A';
▲ return res;
}
string decrypt(in string
string
▲ foreach (c; text.toupper) {
▲ res ~= (c - key[j] + 26) % 26 + 'A';
▲ return res;
}
void main() {
auto key = "VIGENERECIPHER";
Line 354 ⟶ 338:
" The jaws that bite, the claws that catch!";
auto enc = encrypt(ori, key);
writeln(enc, "\n", decrypt(enc, key));
}</lang>
Output:
<pre>WMCEEIKLGRPIFVMEUGXQPWQVIOIAVEYXUEKFKBTALVXTGAFXYEVKPAGY
BEWARETHEJABBERWOCKMYSONTHEJAWSTHATBITETHECLAWSTHATCATCH</pre>
|