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


      key$ = "LEMON"
      plaintext$ = "ATTACK AT DAWN"
      ciphertext$ = FNencrypt(plaintext$, key$)
      PRINT "Key = """ key$ """"
      PRINT "Plaintext  = """ plaintext$ """"
      PRINT "Ciphertext = """ ciphertext$ """"
      PRINT "Decrypted  = """ FNdecrypt(ciphertext$, key$) """"
      END
 
      DEF FNencrypt(plain$, key$)
      LOCAL i%, k%, n%, o$
      plain$ = FNupper(plain$)
      key$ = FNupper(key$)
      FOR i% = 1 TO LEN(plain$)
        n% = ASCMID$(plain$, i%)
        IF n% >= 65 IF n% <= 90 THEN
          o$ += CHR$(65 + (n% + ASCMID$(key$, k%+1)) MOD 26)
          k% = (k% + 1) MOD LEN(key$)
        ENDIF
      NEXT
      = o$
 
      DEF FNdecrypt(cipher$, key$)
      LOCAL i%, k%, n%, o$
      cipher$ = FNupper(cipher$)
      key$ = FNupper(key$)
      FOR i% = 1 TO LEN(cipher$)
        n% = ASCMID$(cipher$, i%)
        o$ += CHR$(65 + (n% + 26 - ASCMID$(key$, k%+1)) MOD 26)
        k% = (k% + 1) MOD LEN(key$)
      NEXT
      = o$
 
      DEF FNupper(A$)
      LOCAL A%,C%
      FOR A% = 1 TO LEN(A$)
        C% = ASCMID$(A$,A%)
        IF C% >= 97 IF C% <= 122 MID$(A$,A%,1) = CHR$(C%-32)
      NEXT
      = A$