added encodings

This commit is contained in:
Stefan Friese 2022-05-19 23:55:26 +02:00
parent 67c0f553f7
commit ff411ed1bd
4 changed files with 78 additions and 9 deletions

View File

@ -1,5 +1,15 @@
# Revision history for based # Revision history for based
## 0.1.0.0 -- YYYY-mm-dd ## 0.1.0.0 -- 2022-05-17
* First version. Released on an unsuspecting world. * First version. Released on an unsuspecting world.
## 0.2.0.0 -- 2022-05-19
* Added the following based and encodings
* Decimal to hex
* Hex to decmial
* Xxencoding
* UuEncoding
* YEncoding
* Quoted-Printable

68
Main.hs
View File

@ -4,6 +4,12 @@
module Main where module Main where
import System.Console.CmdArgs import System.Console.CmdArgs
import Control.Arrow import Control.Arrow
import Numeric (showHex, showIntAtBase)
import Data.Char (intToDigit)
import Data.Char (ord, chr)
import TextShow (toText)
import Text.XML.HXT.DOM.Util (stringToHexString, hexStringToInt, intToHexString, charToHexString, decimalStringToInt)
import TextShow.Data.Integral (showbBin, showbHex)
import qualified Data.Either.Unwrap as U import qualified Data.Either.Unwrap as U
import qualified Codec.Binary.Base91 as B91 import qualified Codec.Binary.Base91 as B91
import qualified Codec.Binary.Base85 as B85 import qualified Codec.Binary.Base85 as B85
@ -11,6 +17,10 @@ import qualified Codec.Binary.Base64 as B64
import qualified Data.Word.Base62 as B62 import qualified Data.Word.Base62 as B62
import qualified Codec.Binary.Base32 as B32 import qualified Codec.Binary.Base32 as B32
import qualified Codec.Binary.Base16 as B16 import qualified Codec.Binary.Base16 as B16
import qualified Codec.Binary.QuotedPrintable as QP
import qualified Codec.Binary.Uu as UU
import qualified Codec.Binary.Xx as XX
import qualified Codec.Binary.Yenc as Y
import qualified Data.Bytes as Bytes import qualified Data.Bytes as Bytes
import qualified Data.Bytes.Text.Ascii as ASCII import qualified Data.Bytes.Text.Ascii as ASCII
import Data.ByteString.UTF8 as BSU -- from utf8-string import Data.ByteString.UTF8 as BSU -- from utf8-string
@ -21,16 +31,28 @@ data Based = Decode {
b85 :: Bool, b85 :: Bool,
b64 :: Bool, b64 :: Bool,
b62 :: Bool, b62 :: Bool,
b58 :: Bool,
b32 :: Bool, b32 :: Bool,
b16 :: Bool b16 :: Bool,
b10 :: Bool,
qp :: Bool,
uu :: Bool,
xx :: Bool,
yenc :: Bool
} }
| Encode { | Encode {
b91 :: Bool, b91 :: Bool,
b85 :: Bool, b85 :: Bool,
b64 :: Bool, b64 :: Bool,
b62 :: Bool, b62 :: Bool,
b58 :: Bool,
b32 :: Bool, b32 :: Bool,
b16 :: Bool b16 :: Bool,
b10 :: Bool,
qp :: Bool,
uu :: Bool,
xx :: Bool,
yenc :: Bool
} }
deriving(Show, Data, Typeable) deriving(Show, Data, Typeable)
@ -43,10 +65,22 @@ dec64 = C.unpack . U.fromRight . B64.decode . BSU.fromString
enc64 = C.unpack . B64.encode . BSU.fromString enc64 = C.unpack . B64.encode . BSU.fromString
dec62 = show . B62.decode64 . ASCII.fromString dec62 = show . B62.decode64 . ASCII.fromString
enc62 = show . B62.decode64 . ASCII.fromString enc62 = show . B62.decode64 . ASCII.fromString
dec58 = show
enc58 = show
dec32 = C.unpack . U.fromRight . B32.decode . BSU.fromString dec32 = C.unpack . U.fromRight . B32.decode . BSU.fromString
enc32 = C.unpack . B32.encode . BSU.fromString enc32 = C.unpack . B32.encode . BSU.fromString
dec16 = C.unpack . U.fromRight . B16.decode . BSU.fromString dec16 = C.unpack . U.fromRight . B16.decode . BSU.fromString
enc16 = C.unpack . B16.encode . BSU.fromString enc16 = C.unpack . B16.encode . BSU.fromString
dec10 = show . hexStringToInt
enc10 = C.unpack . BSU.fromString . intToHexString . decimalStringToInt -- Depending on what you want, do enc10 = show . map ord
decqp = C.unpack . U.fromRight . QP.decode . BSU.fromString
encqp = C.unpack . QP.encode . BSU.fromString
decuu = C.unpack . U.fromRight . UU.decode . BSU.fromString
encuu = C.unpack . UU.encode . BSU.fromString
decxx = C.unpack . U.fromRight . XX.decode . BSU.fromString
encxx = C.unpack . XX.encode . BSU.fromString
decy = C.unpack . U.fromRight . Y.decode . BSU.fromString
ency = C.unpack . Y.encode . BSU.fromString
optionHandler Decode{b91=True} = dec91 optionHandler Decode{b91=True} = dec91
@ -57,18 +91,36 @@ optionHandler Decode{b64=True} = dec64
optionHandler Encode{b64=True} = enc64 optionHandler Encode{b64=True} = enc64
optionHandler Decode{b62=True} = dec62 optionHandler Decode{b62=True} = dec62
optionHandler Encode{b62=True} = enc62 optionHandler Encode{b62=True} = enc62
optionHandler Decode{b58=True} = dec58
optionHandler Encode{b58=True} = enc58
optionHandler Decode{b32=True} = dec32 optionHandler Decode{b32=True} = dec32
optionHandler Encode{b32=True} = enc32 optionHandler Encode{b32=True} = enc32
optionHandler Decode{b16=True} = dec16 optionHandler Decode{b16=True} = dec16
optionHandler Encode{b16=True} = enc16 optionHandler Encode{b16=True} = enc16
optionHandler Decode{b10=True} = dec10
optionHandler Encode{b10=True} = enc10
optionHandler Decode{qp=True} = decqp
optionHandler Encode{qp=True} = encqp
optionHandler Encode{uu=True} = decuu
optionHandler Decode{uu=True} = encuu
optionHandler Decode{xx=True} = decxx
optionHandler Encode{xx=True} = encxx
optionHandler Decode{yenc=True} = decy
optionHandler Encode{yenc=True} = ency
decode_ = Decode { decode_ = Decode {
b91 = def &= help "decode base91", b91 = def &= help "decode base91",
b85 = def &= help "decode base85", b85 = def &= help "decode base85",
b64 = def &= help "decode base64", b64 = def &= help "decode base64",
b62 = def &= help "decode base62", b62 = def &= help "decode base62",
b58 = def &= help "decode base58",
b32 = def &= help "decode base32", b32 = def &= help "decode base32",
b16 = def &= help "decode base16" b16 = def &= help "decode base16",
b10 = def &= help "decode base10 to hex",
qp = def &= help "decode quoted-printable",
uu = def &= help "decode uu",
xx = def &= help "decode xx",
yenc = def &= help "decode yEncode"
} &= help "Decode chosen base" &=auto } &= help "Decode chosen base" &=auto
encode_ = Encode { encode_ = Encode {
@ -76,8 +128,14 @@ encode_ = Encode {
b85 = def &= help "encode base85", b85 = def &= help "encode base85",
b64 = def &= help "encode base64", b64 = def &= help "encode base64",
b62 = def &= help "encode base62", b62 = def &= help "encode base62",
b58 = def &= help "encode base58",
b32 = def &= help "encode base32", b32 = def &= help "encode base32",
b16 = def &= help "encode base16" b16 = def &= help "encode base16",
b10 = def &= help "encode base10 to hex",
qp = def &= help "encode quoted-printable",
uu = def &= help "encode uu",
xx = def &= help "encode xx",
yenc = def &= help "encode yEncode"
} &= help "Encode chosen base" } &= help "Encode chosen base"
main = cmdArgs (modes[decode_, encode_] &= help "Anybased, when Cyberchef simply doesn't cut it. " &= program "based" &= summary "Based v0.1") >>= interact . optionHandler main = cmdArgs (modes[decode_, encode_] &= help "Anybased, when Cyberchef simply doesn't cut it. " &= program "based" &= summary "based v0.1") >>= interact . optionHandler

View File

@ -4,13 +4,14 @@ A commandline tool that lets you encode and decode most of the bases.
Release binary is statically linked via Release binary is statically linked via
```sh ```sh
cabal v2-build --enable-executable-static cabal v2-build --enable-executable-static -O2
``` ```
## Compilation ## Compilation
* If you want to compile your own build, link it dynamically via * If you want to compile your own build, link it dynamically via
```sh ```sh
git clone https://git.stefan.works/whx/based.git
cd based/ cd based/
cabal install cabal install
cabal run cabal run

View File

@ -27,6 +27,6 @@ executable based
main-is: Main.hs main-is: Main.hs
other-modules: MyLib other-modules: MyLib
-- other-extensions: -- other-extensions:
build-depends: base ^>=4.13.0.0, based, cmdargs, sandi, base62, base91, utf8-string, bytestring, byteslice, either-unwrap build-depends: base ^>=4.13.0.0, based, cmdargs, sandi, base62, base91, utf8-string, bytestring, byteslice, either-unwrap, text-show, hxt
-- hs-source-dirs: -- hs-source-dirs:
default-language: Haskell2010 default-language: Haskell2010