-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaesar.hs
More file actions
23 lines (20 loc) · 702 Bytes
/
caesar.hs
File metadata and controls
23 lines (20 loc) · 702 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import Data.Functor
import Data.Char
import qualified Data.Set as S
caesar :: Int -> [Char] -> Int -> [Char]
caesar n s k = map (\c ->
let cc = ord c
rs = if isUpper c then 'A' else 'a'
re = if isUpper c then 'Z' else 'z'
d = 1 + ord re - ord rs
ccb = cc - ord rs
ce = ord rs + (ccb + k) `mod` d
in if isAlpha c
then chr ce
else c
) s
main = do
n <- read <$> getLine
s <- getLine
k <- read <$> getLine
putStrLn $ caesar n s k