Vigenère cipher: Difference between revisions
Content added Content deleted
(Updated to work with Nim 1.4: added missing parameter types; replaced "toUpper" with "toUpperAscii". Also, some other modifications.) |
Alextretyak (talk | contribs) (Added 11l) |
||
Line 18: | Line 18: | ||
* [[Substitution Cipher]] |
* [[Substitution Cipher]] |
||
<br><br> |
<br><br> |
||
=={{header|11l}}== |
|||
{{trans|C++}} |
|||
<lang 11l>F encrypt(key, text) |
|||
V out = ‘’ |
|||
V j = 0 |
|||
L(c) text |
|||
I !c.is_alpha() |
|||
L.continue |
|||
out ‘’= Char(code' (c.uppercase().code + key[j].code - 2 * ‘A’.code) % 26 + ‘A’.code) |
|||
j = (j + 1) % key.len |
|||
R out |
|||
F decrypt(key, text) |
|||
V out = ‘’ |
|||
V j = 0 |
|||
L(c) text |
|||
I !c.is_alpha() |
|||
L.continue |
|||
out ‘’= Char(code' (c.code - key[j].code + 26) % 26 + ‘A’.code) |
|||
j = (j + 1) % key.len |
|||
R out |
|||
V key = ‘VIGENERECIPHER’ |
|||
V original = ‘Beware the Jabberwock, my son! The jaws that bite, the claws that catch!’ |
|||
V encrypted = encrypt(key, original) |
|||
V decrypted = decrypt(key, encrypted) |
|||
print(original) |
|||
print(‘Encrypted: ’encrypted) |
|||
print(‘Decrypted: ’decrypted)</lang> |
|||
{{out}} |
|||
<pre> |
|||
Beware the Jabberwock, my son! The jaws that bite, the claws that catch! |
|||
Encrypted: WMCEEIKLGRPIFVMEUGXQPWQVIOIAVEYXUEKFKBTALVXTGAFXYEVKPAGY |
|||
Decrypted: BEWARETHEJABBERWOCKMYSONTHEJAWSTHATBITETHECLAWSTHATCATCH |
|||
</pre> |
|||
=={{header|Ada}}== |
=={{header|Ada}}== |