21 lines
541 B
Haskell
21 lines
541 B
Haskell
module Encoding.Base16
|
|
( enc16
|
|
, dec16
|
|
) where
|
|
|
|
import qualified Data.ByteString.Char8 as C
|
|
import Data.ByteString.UTF8 as BSU
|
|
import qualified Codec.Binary.Base16 as B16
|
|
import qualified Data.Text as T
|
|
import qualified Data.Text.Encoding as T
|
|
import qualified Data.Text.IO as T
|
|
|
|
dec16 :: String -> String
|
|
dec16 input =
|
|
case B16.decode (BSU.fromString input) of
|
|
Right decoded -> T.unpack (T.decodeUtf8 decoded)
|
|
Left _ -> "Error decoding Base16.\n"
|
|
|
|
enc16 :: String -> String
|
|
enc16 = C.unpack . B16.encode . BSU.fromString
|