Task

Implement a   Vigenère cypher,   both encryption and decryption.

The program should handle keys and text of unequal length,
and should capitalize everything and discard non-alphabetic characters. 

(If your program handles non-alphabetic characters in another way,
make a note of it.)



Related tasks

   Caesar cipher
   Rot-13
   Substitution Cipher


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