       PROGRAM CAESAR
************************************************************************
* This program encodes or decodes a message using the Caesar cipher    *
* Variables used are:                                                  *
*    MSG     :  message to encode                                      *
*    CMSG    :  coded message                                          *
************************************************************************

       CHARACTER*99 MSG, CMSG

       MSG = 'This is an amazing secret message!'
       CALL ENCIPHER(MSG,CMSG)
       PRINT *, 'The enciphered message is:  ', CMSG
       CALL DECIPHER(CMSG,MSG)
       PRINT *, 'The deciphered message is:  ', MSG
       END

       SUBROUTINE SHIFT_MESSAGE(MESSAGE,SHIFT,SMESSAGE)
          CHARACTER*99 MESSAGE, SMESSAGE
          INTEGER SHIFT, CODE
          DO 1000 I = 1,LEN(MESSAGE)
             CODE = ICHAR(MESSAGE(I:I))
             IF ((CODE.GE.65).AND.(CODE.LE.90)) THEN
               CODE = MOD(CODE-39+SHIFT,26)+65            
             ELSE IF ((CODE.GE.97).AND.(CODE.LE.122)) THEN
               CODE = MOD(CODE-71+SHIFT,26)+65                  
             END IF
             SMESSAGE(I:I) = CHAR(CODE)
1000      CONTINUE
          RETURN
       END
       
       SUBROUTINE ENCIPHER(MESSAGE,CMESSAGE)
          CHARACTER*99 MESSAGE, CMESSAGE
          CALL SHIFT_MESSAGE(MESSAGE,3,CMESSAGE)
          RETURN
       END
              
       SUBROUTINE DECIPHER(CMESSAGE,MESSAGE)
          CHARACTER*99 MESSAGE, CMESSAGE
          CALL SHIFT_MESSAGE(CMESSAGE,-3,MESSAGE)
          RETURN
       END