File: Rot13.hs

package info (click to toggle)
haskell-snap-server 0.9.4.5-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 428 kB
  • sloc: haskell: 4,300; sh: 46; makefile: 2
file content (19 lines) | stat: -rw-r--r-- 512 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
module Test.Common.Rot13 (rot13) where

import           Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as S
import           Data.Char

rotone :: Char -> Char
rotone x | acc x = f
         | otherwise = x
  where
    aA    = ord 'A'
    aa    = ord 'a'
    xx    = ord x
    f     = g $ if isAsciiUpper x then aA else aa
    g st  = chr $ st + (xx - st + 13) `mod` 26
    acc c = isAlpha c && (isAsciiUpper c || isAsciiLower c)

rot13 :: ByteString -> ByteString
rot13 = S.map rotone