12345678910111213141516171819202122 |
- -- Slide 58
- import Data.Char
- cechar n c = chr ((mod ((ord c) + n - ord 'a') ((ord 'z') - ord 'a' + 1)) + ord 'a')
- cesar n = map (cechar n)
- inlinecesar n s = map (chr.(+ ord 'a').(flip mod 26).(+ n).(subtract (ord 'a')).ord) s
- getCorrectValue::IO Int
- getCorrectValue = do
- x <- getLine
- let i = (read x)::Int
- if i >= 0 && i < 26 then return i else getCorrectValue
- main::IO ()
- main = do
- n <- getCorrectValue
- s <- getLine
- putStrLn (cesar n s)
- putStrLn (inlinecesar n s)
|