Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rotN :: forall a. (Bounded a, Enum a) => a -> a
- rotN c = toEnum rotation
- where alphabetSize = 1 + fromEnum (maxBound :: a)
- halfAlphabet = alphabetSize `div` 2
- offset = fromEnum c + halfAlphabet
- rotation = offset `mod` alphabetSize
- rotNdecoder :: forall a. (Bounded a, Enum a) => a -> a
- rotNdecoder c = toEnum rotation
- where n = 1 + fromEnum (maxBound :: a)
- halfN = n `div` 2
- offset = if even n
- then fromEnum c + halfN
- else 1 + fromEnum c + halfN
- rotation = offset `mod` n
- rotEncoder :: (Bounded a, Enum a) => [a] -> [a]
- rotEncoder text = map rotN text
- rotDecoder :: (Bounded a, Enum a) => [a] -> [a]
- rotDecoder text = map rotNdecoder text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement