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


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)