Vigenère cipher: Difference between revisions

Content deleted Content added
→‎{{header|AutoHotkey}}: AutoHotkey example added
No edit summary
Line 726:
<pre>WMCEEIKLGRPIFVMEUGXQPWQVIOIAVEYXUEKFKBTALVXTGAFXYEVKPAGY
BEWARETHEJABBERWOCKMYSONTHEJAWSTHATBITETHECLAWSTHATCATCH</pre>
 
=={{header|JavaScript}}==
<lang javascript><html><head><title>Vigenère</title></head>
Line 756 ⟶ 757:
disp("Original:" + msg + "\nEncoded: " + enc + "\nDecoded: " + dec);
</script></body></html></lang>
 
=={{header|Liberty BASIC}}==
<lang lb>
ori$ = "Beware the Jabberwock, my son! The jaws that bite, the claws that catch!"
key$ = filter$("vigenerecipher")
print ori$
print key$
enc$ = encrypt$(ori$, key$)
print enc$
dec$ = decrypt$(enc$, key$)
print dec$
 
end
 
function encrypt$(text$, key$)
flt$ = filter$(text$)
encrypt$ = ""
j = 1
for i = 1 to len(flt$)
m$ = mid$(flt$, i, 1)
m = asc(m$)-asc("A")
k$ = mid$(key$, j, 1)
k = asc(k$)-asc("A")
j = (j mod len(key$)) + 1
c = (m + k) mod 26
c$=chr$(asc("A")+c)
encrypt$=encrypt$+c$
next
end function
 
function decrypt$(flt$, key$)
decrypt$ = ""
j = 1
for i = 1 to len(flt$)
m$ = mid$(flt$, i, 1)
m = asc(m$)-asc("A")
k$ = mid$(key$, j, 1)
k = asc(k$)-asc("A")
j = (j mod len(key$)) + 1
c = (m - k + 26) mod 26
c$=chr$(asc("A")+c)
decrypt$=decrypt$+c$
next
end function
 
function filter$(ori$)
'a..z A..Z go caps, other skipped
filter$=""
for i = 1 to len(ori$)
c$ = upper$(mid$(ori$,i,1))
if instr("ABCDEFGHIJKLMNOPQRSTUVWXYZ", c$) then filter$ = filter$ + c$
next
end function
</lang>
Beware the Jabberwock, my son! The jaws that bite, the claws that catch!
VIGENERECIPHER
WMCEEIKLGRPIFVMEUGXQPWQVIOIAVEYXUEKFKBTALVXTGAFXYEVKPAGY
BEWARETHEJABBERWOCKMYSONTHEJAWSTHATBITETHECLAWSTHATCATCH
 
=={{header|Lua}}==
<lang lua>function Encrypt( _msg, _key )