0

My First -not so- Non-trivial Haskell Program

To write a caeser cipher given a string (all in lower case) and the shift count:

rotateLetter :: Char -> Int -> Char
rotateLetter a 0 = a
rotateLetter 'z' n = rotateLetter 'a' (n-1)
rotateLetter a n = rotateLetter (succ a) (n - 1)

caeserCipher :: [Char] -> Int -> [Char]
caeserCipher "" n = ""
caeserCipher (x:xs) n = (rotateLetter x n) : caeserCipher xs n
Advertisements