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


 
{def vigenere
 {def vigenere.map
  {lambda {:code :key :txt}
   {S.map
    {{lambda {:code :txt :key :i} 
     {W.code2char 
      {+ {% {+ {W.char2code {W.get :i :txt}} 
               {if :code 
                then       {W.char2code {W.get {% :i {W.length :key}} :key}}
                else {- 26 {W.char2code {W.get {% :i {W.length :key}} :key}}} }}
            26}
         65}} } :code :txt :key}
    {S.serie 0 {- {W.length :txt} 1}}} }}
 {lambda {:code :key :txt}
  {S.replace \s by in {vigenere.map :code :key {S.replace \s by in :txt}}} }}
-> vigenere
 
1) encode: {vigenere true LEMON ATTACK AT DAWN} 
-> LXFOPVEFRNHR
 
2) decode: {vigenere false LEMON LXFOPVEFRNHR}
-> ATTACKATDAWN
 
 