added rotate functions for n rotations of the alphabet
This commit is contained in:
parent
778f2c6e7a
commit
146293eeb4
18
CHANGELOG.md
18
CHANGELOG.md
|
@ -1,6 +1,16 @@
|
|||
Revision history for based
|
||||
|
||||
0.4.3.0 -- 2024-05-22
|
||||
|
||||
Added rotate function to encode and decode
|
||||
Added solver function to decode, to automatically solve some of the encodings, ongoing
|
||||
Added tests for some of the encode and decode functions, ongoing
|
||||
Added unicode support for most of the encoding/decoding functions, ongoing
|
||||
Modularized Encodings to a lib, instead having everything in a single flat file
|
||||
Cleanup of cabal file
|
||||
|
||||
0.4.2.0 -- 2023-07-25
|
||||
|
||||
Changed Base64 decoding to Base64 lenient
|
||||
Cleanup
|
||||
|
||||
|
@ -17,7 +27,13 @@ Revision history for based
|
|||
|
||||
0.2.0.0 -- 2022-05-19
|
||||
|
||||
Added the following bases and encodings * Decimal to hex * Hex to decmial * Xxencoding * UuEncoding * YEncoding * Quoted-Printable
|
||||
Added the following bases and encodings
|
||||
* Decimal to hex
|
||||
* Hex to decmial
|
||||
* Xxencoding
|
||||
* UuEncoding
|
||||
* YEncoding
|
||||
* Quoted-Printable
|
||||
|
||||
0.1.0.0 -- 2022-05-17
|
||||
|
||||
|
|
15
app/Main.hs
15
app/Main.hs
|
@ -23,6 +23,7 @@ import Encoding.Xx (encxx, decxx)
|
|||
import Encoding.QuotedPrintable (encqp, decqp)
|
||||
import Encoding.UnixToUnix (encuu, decuu)
|
||||
import Encoding.Yenc (ency, decy)
|
||||
import Encoding.Rotate (rotate)
|
||||
|
||||
|
||||
data Based = Decode {
|
||||
|
@ -42,6 +43,7 @@ data Based = Decode {
|
|||
uu :: Bool,
|
||||
xx :: Bool,
|
||||
yenc :: Bool,
|
||||
rot :: Maybe Int,
|
||||
solve :: Bool
|
||||
}
|
||||
| Encode {
|
||||
|
@ -60,8 +62,9 @@ data Based = Decode {
|
|||
qp :: Bool,
|
||||
uu :: Bool,
|
||||
xx :: Bool,
|
||||
yenc :: Bool
|
||||
}
|
||||
yenc :: Bool,
|
||||
rot :: Maybe Int
|
||||
}
|
||||
deriving(Show, Data, Typeable)
|
||||
|
||||
-- helper functions
|
||||
|
@ -175,6 +178,8 @@ optionHandler Decode{xx=True} = decxx
|
|||
optionHandler Encode{xx=True} = encxx
|
||||
optionHandler Decode{yenc=True} = decy
|
||||
optionHandler Encode{yenc=True} = ency
|
||||
optionHandler Encode{rot=Just n} = rotate n
|
||||
optionHandler Decode{rot=Just n} = rotate n
|
||||
optionHandler Decode{solve=True} = solveEnc
|
||||
|
||||
decodeMode :: Based
|
||||
|
@ -195,6 +200,7 @@ decodeMode = Decode {
|
|||
uu = def &= help "decode uu",
|
||||
xx = def &= help "decode xx",
|
||||
yenc = def &= help "decode yEncode",
|
||||
rot = def &= help "rotate characters by n positions",
|
||||
solve = def &= help "solve encoding"
|
||||
} &= help "Decode chosen base" &=auto
|
||||
|
||||
|
@ -215,8 +221,9 @@ encodeMode = Encode {
|
|||
qp = def &= help "encode quoted-printable",
|
||||
uu = def &= help "encode uu",
|
||||
xx = def &= help "encode xx",
|
||||
yenc = def &= help "encode yEncode"
|
||||
yenc = def &= help "encode yEncode",
|
||||
rot = def &= help "rotate characters by n positions"
|
||||
} &= help "Encode chosen base"
|
||||
|
||||
main :: IO()
|
||||
main = cmdArgs (modes[decodeMode, encodeMode] &= help "Anybased, when Cyberchef simply doesn't cut it.\nTo see every parameter of every mode use --help=all" &= program "based" &= summary "based v0.4") >>= interact . optionHandler
|
||||
main = cmdArgs (modes[decodeMode, encodeMode] &= help "Based, when Cyberchef doesn't cut it.\nTo see every parameter of every mode use --help=all" &= program "based" &= summary "based v0.4") >>= interact . optionHandler
|
||||
|
|
|
@ -23,6 +23,7 @@ library
|
|||
Encoding.UnixToUnix
|
||||
Encoding.Xx
|
||||
Encoding.Yenc
|
||||
Encoding.Rotate
|
||||
other-modules:
|
||||
-- Data.Bytes.Text.Ascii
|
||||
build-depends:
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
module Encoding.Rotate
|
||||
( rotate ) where
|
||||
|
||||
import Data.Maybe (fromMaybe)
|
||||
|
||||
upperCase = ['A' .. 'Z']
|
||||
lowerCase = ['a' .. 'z']
|
||||
|
||||
-- rotate :: Int * -> String
|
||||
rotate :: Int -> String -> String
|
||||
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)
|
||||
|
||||
transp :: Int -> [Char] -> [(Char, Char)]
|
||||
transp n x = zip x ((drop n x) ++ (take n x))
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue