PROGRAM Caesar_Cipher
!------------------------------------------------------------------------
!  This program encrypts a character string using the Caesar cipher     
!  scheme. Variables used are the following:                                                             
!    String     : string to be encrypted                                   
!    Symbol     : an individual character of the message                  
!    Key        : integer to be added in encrypting the message              
!    ASCII_Code : ASCII code for SYMBOL                                   
!    I          : counter                                                       
!                                                                      
!  Input:  String and Key                                              
!  Output: User prompts and String (encrypted)                              
!------------------------------------------------------------------------

   IMPLICIT NONE

   CHARACTER(LEN = 80) :: String, Symbol*1       

   INTEGER :: Key, ASCII_Code, I
          
! Get the string to be encrypted and the key
   PRINT *, "Enter string to be encrypted (end with !):"
   READ "(A)", String
   PRINT *,  "Enter key:"
   READ *, Key

! Extract the first character in the string
   I = 1
   Symbol = String(1:1)

! Do the folloiwng
  DO
    IF (I == LEN(String) .OR. Symbol == "!") EXIT
    ! If end of string, terminate repetition
    ! otherwise continue with the following
 
    ASCII_Code = MOD((IACHAR(Symbol) - 32 + KEY), 95) + 32
    String(I:I) = ACHAR(ASCII_Code)
    I = I + 1
    Symbol = String(I:I)
  END DO

  PRINT *, "Encrypted string:"
  PRINT *, String
      
END PROGRAM Caesar_Cipher