23 lines
467 B
Haskell
23 lines
467 B
Haskell
|
|
module Encoding.Rotate
|
||
|
|
( rotate ) where
|
||
|
|
|
||
|
|
import Data.Maybe (fromMaybe)
|
||
|
|
|
||
|
|
upperCase = ['A' .. 'Z']
|
||
|
|
lowerCase = ['a' .. 'z']
|
||
|
|
|
||
|
|
-- rotate :: Int * -> String
|
||
|
|
rotate :: Int -> String -> String
|
||
|
|
rotate n s = map (rotchar n) s
|
||
|
|
where
|
||
|
|
rotchar n c =
|
||
|
|
case (lookup c $ transp n lowerCase) of
|
||
|
|
Just x -> x
|
||
|
|
Nothing -> fromMaybe c (lookup c $ transp n upperCase)
|
||
|
|
|
||
|
|
transp :: Int -> [Char] -> [(Char, Char)]
|
||
|
|
transp n x = zip x ((drop n x) ++ (take n x))
|
||
|
|
|
||
|
|
|
||
|
|
|