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


 
  100 :
  110  REM  VIGENERE CIPHER
  120 :
  200  REM  SET-UP
  210 K$ = "LEMON": PRINT "KEY: "; K$
  220 PT$ = "ATTACK AT DAWN": PRINT "PLAIN TEXT: ";PT$
  230  DEF  FN MOD(A) = A -  INT (A / 26) * 26 
  300  REM  ENCODING
  310 K = 1
  320  FOR I = 1 TO  LEN (PT$)
  330  IF  ASC ( MID$ (PT$,I,1)) < 65
       OR  ASC ( MID$ (PT$,I,1)) > 90 THEN  NEXT I
  340 TV =  ASC ( MID$ (PT$,I,1)) - 65
  350 KV =  ASC ( MID$ (K$,K,1)) - 65
  360 CT$ = CT$ +  CHR$ ( FN MOD(TV + KV) + 65)
  370 K = K + 1: IF K >  LEN (K$) THEN K = 1      
  380  NEXT I
  390  PRINT "CIPHER TEXT: ";CT$
  400  REM  DECODING
  410 K = 1
  420  FOR I = 1 TO  LEN (CT$)
  430 TV =  ASC ( MID$ (CT$,I,1)) - 65
  440 KV =  ASC ( MID$ (K$,K,1)) -  65
  450 T = TV - KV: IF T < 0 THEN T = T + 26
  460 DT$ = DT$ +  CHR$ (T + 65)
  470 K = K + 1: IF K >  LEN (K$) THEN K = 1
  480  NEXT I
  490  PRINT "DECRYPTED TEXT: ";DT$ 