Jump to content

Vigenère cipher: Difference between revisions

Added Arturo implementation
(Added 11l)
(Added Arturo implementation)
Line 235:
CIPHER TEXT: LXFOPVEFRNHR
DECRYPTED TEXT: ATTACKATDAWN
 
=={{header|Arturo}}==
 
<lang rebol>Letters: append `A`..`Z` `a`..`z`
encrypt: function [msg, key][
pos: 0
result: new ""
loop msg 'c ->
if in? c Letters [
'result ++ to :char (((to :integer key\[pos]) + to :integer upper c) % 26) + to :integer `A`
pos: (pos + 1) % size key
]
return result
]
 
decrypt: function [msg, key][
pos: 0
result: new ""
loop msg 'c [
'result ++ to :char ((26 + (to :integer c) - to :integer key\[pos]) % 26) + to :integer `A`
pos: (pos + 1) % size key
]
return result
]
 
text: "Beware the Jabberwock, my son! The jaws that bite, the claws that catch!"
key: "VIGENERECIPHER"
 
encr: encrypt text key
decr: decrypt encr key
 
print text
print encr
print decr</lang>
 
{{out}}
 
<pre>Beware the Jabberwock, my son! The jaws that bite, the claws that catch!
WMCEEIKLGRPIFVMEUGXQPWQVIOIAVEYXUEKFKBTALVXTGAFXYEVKPAGY
BEWARETHEJABBERWOCKMYSONTHEJAWSTHATBITETHECLAWSTHATCATCH</pre>
 
=={{header|AutoHotkey}}==
1,532

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.