changed rotate to match ByteStrings instead of Strings
This commit is contained in:
parent
fbb10d0edf
commit
b91f110f42
22
app/Main.hs
22
app/Main.hs
|
@ -26,7 +26,7 @@ import Encoding.Xx (encxx, decxx)
|
||||||
import Encoding.QuotedPrintable (encqp, decqp)
|
import Encoding.QuotedPrintable (encqp, decqp)
|
||||||
import Encoding.UnixToUnix (encuu, decuu)
|
import Encoding.UnixToUnix (encuu, decuu)
|
||||||
import Encoding.Yenc (ency, decy)
|
import Encoding.Yenc (ency, decy)
|
||||||
--import Encoding.Rotate (rotate)
|
import Encoding.Rotate (rotate)
|
||||||
|
|
||||||
|
|
||||||
data Based = Decode {
|
data Based = Decode {
|
||||||
|
@ -46,8 +46,8 @@ data Based = Decode {
|
||||||
qp :: Bool,
|
qp :: Bool,
|
||||||
uu :: Bool,
|
uu :: Bool,
|
||||||
xx :: Bool,
|
xx :: Bool,
|
||||||
yenc :: Bool
|
yenc :: Bool,
|
||||||
-- rot :: Maybe Int,
|
rot :: Maybe Int
|
||||||
-- solve :: Bool
|
-- solve :: Bool
|
||||||
}
|
}
|
||||||
| Encode {
|
| Encode {
|
||||||
|
@ -67,8 +67,8 @@ data Based = Decode {
|
||||||
qp :: Bool,
|
qp :: Bool,
|
||||||
uu :: Bool,
|
uu :: Bool,
|
||||||
xx :: Bool,
|
xx :: Bool,
|
||||||
yenc :: Bool
|
yenc :: Bool,
|
||||||
-- rot :: Maybe Int
|
rot :: Maybe Int
|
||||||
}
|
}
|
||||||
deriving(Show, Data, Typeable)
|
deriving(Show, Data, Typeable)
|
||||||
|
|
||||||
|
@ -185,8 +185,8 @@ optionHandler Decode{xx=True} = decxx
|
||||||
optionHandler Encode{xx=True} = encxx
|
optionHandler Encode{xx=True} = encxx
|
||||||
optionHandler Decode{yenc=True} = decy
|
optionHandler Decode{yenc=True} = decy
|
||||||
optionHandler Encode{yenc=True} = ency
|
optionHandler Encode{yenc=True} = ency
|
||||||
--optionHandler Encode{rot=Just n} = rotate n
|
optionHandler Encode{rot=Just n} = rotate n
|
||||||
--optionHandler Decode{rot=Just n} = rotate n
|
optionHandler Decode{rot=Just n} = rotate n
|
||||||
--optionHandler Decode{solve=True} = solveEnc
|
--optionHandler Decode{solve=True} = solveEnc
|
||||||
|
|
||||||
decodeMode :: Based
|
decodeMode :: Based
|
||||||
|
@ -207,8 +207,8 @@ decodeMode = Decode {
|
||||||
qp = def &= help "decode quoted-printable",
|
qp = def &= help "decode quoted-printable",
|
||||||
uu = def &= help "decode uu",
|
uu = def &= help "decode uu",
|
||||||
xx = def &= help "decode xx",
|
xx = def &= help "decode xx",
|
||||||
yenc = def &= help "decode yEncode"
|
yenc = def &= help "decode yEncode",
|
||||||
-- rot = def &= help "rotate characters by n positions",
|
rot = def &= help "rotate characters by n positions"
|
||||||
-- solve = def &= help "solve encoding"
|
-- solve = def &= help "solve encoding"
|
||||||
} &= help "Decode chosen base" &=auto
|
} &= help "Decode chosen base" &=auto
|
||||||
|
|
||||||
|
@ -230,8 +230,8 @@ encodeMode = Encode {
|
||||||
qp = def &= help "encode quoted-printable",
|
qp = def &= help "encode quoted-printable",
|
||||||
uu = def &= help "encode uu",
|
uu = def &= help "encode uu",
|
||||||
xx = def &= help "encode xx",
|
xx = def &= help "encode xx",
|
||||||
yenc = def &= help "encode yEncode"
|
yenc = def &= help "encode yEncode",
|
||||||
-- rot = def &= help "rotate characters by n positions"
|
rot = def &= help "rotate characters by n positions"
|
||||||
} &= help "Encode chosen base"
|
} &= help "Encode chosen base"
|
||||||
|
|
||||||
--main :: IO()
|
--main :: IO()
|
||||||
|
|
|
@ -2,21 +2,33 @@ module Encoding.Rotate
|
||||||
( rotate ) where
|
( rotate ) where
|
||||||
|
|
||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe (fromMaybe)
|
||||||
|
import Data.ByteString as B
|
||||||
|
import qualified Data.ByteString.Char8 as BC
|
||||||
|
|
||||||
upperCase = ['A' .. 'Z']
|
upperCase = BC.pack ['A' .. 'Z']
|
||||||
lowerCase = ['a' .. 'z']
|
lowerCase = BC.pack ['a' .. 'z']
|
||||||
|
|
||||||
-- rotate :: Int * -> String
|
-- rotate :: Int -> String -> String
|
||||||
rotate :: Int -> String -> String
|
-- rotate n s = map (rotchar n) s
|
||||||
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)
|
||||||
|
rotate :: Int -> BC.ByteString -> BC.ByteString
|
||||||
|
rotate n s = BC.map (rotchar n) s
|
||||||
where
|
where
|
||||||
rotchar n c =
|
rotchar :: Int -> Char -> Char
|
||||||
|
rotchar n c =
|
||||||
case (lookup c $ transp n lowerCase) of
|
case (lookup c $ transp n lowerCase) of
|
||||||
Just x -> x
|
Just x -> x
|
||||||
Nothing -> fromMaybe c (lookup c $ transp n upperCase)
|
Nothing -> fromMaybe c (lookup c $ transp n upperCase)
|
||||||
|
|
||||||
transp :: Int -> [Char] -> [(Char, Char)]
|
|
||||||
transp n x = zip x ((drop n x) ++ (take n x))
|
-- transp :: Int -> [Char] -> [(Char, Char)]
|
||||||
|
-- transp n x = zip x ((drop n x) ++ (take n x))
|
||||||
|
transp :: Int -> BC.ByteString -> [(Char, Char)]
|
||||||
|
transp n x = Prelude.zip (BC.unpack x) (BC.unpack $ BC.append (BC.drop n x) (BC.take n x))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue