import Data.Char                                                            -- Needed for "ord" and "chr"

alphabetLength :: Int
alphabetLength = 26

isAlphabetic :: Char -> Bool
isAlphabetic char = char >= 'A' && char <= 'Z'

encryptChar :: Char -> Int -> Int
encryptChar char shift = if isAlphabetic char                               -- Only encrypt A...Z
                            then (if ord char + shift > ord 'Z'             -- "Z" with shift 3 becomes "C" and not "]" 
                                    then ord char + shift - alphabetLength
                                  else ord char + shift)
                         else ord char

decryptChar :: Char -> Int -> Int
decryptChar char shift = if isAlphabetic char
                            then (if ord char - shift < ord 'A'
                                    then ord char - shift + alphabetLength
                                  else ord char - shift)
                         else ord char

encrypt :: String -> Int -> String
encrypt string shift = [chr (encryptChar (toUpper x) shift) | x <- string]  -- "Loop" through string to encrypt char by char

decrypt :: String -> Int -> String
decrypt string shift = [chr (decryptChar (toUpper x) shift) | x <- string]

main :: IO()
main = print(decrypt "KHOOR, ZRUOG!" 3)

