added more bases to the solver function
This commit is contained in:
parent
e9d73d4062
commit
24cbf07357
16
Main.hs
16
Main.hs
|
@ -6,10 +6,12 @@ import System.Console.CmdArgs
|
||||||
import Control.Arrow
|
import Control.Arrow
|
||||||
import Data.Text (pack, unpack)
|
import Data.Text (pack, unpack)
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
|
import Data.Text (Text)
|
||||||
import qualified Data.Text.Lazy as TL
|
import qualified Data.Text.Lazy as TL
|
||||||
import Data.Text.Lazy.Builder (toLazyText)
|
import Data.Text.Lazy.Builder (toLazyText)
|
||||||
import Data.Text.Encoding (encodeUtf8)
|
import Data.Text.Encoding (decodeUtf8With, decodeUtf8, encodeUtf8)
|
||||||
import Data.Maybe (fromJust, fromMaybe)
|
import Data.Maybe (fromJust, fromMaybe)
|
||||||
|
import Data.Text.Encoding.Error (lenientDecode)
|
||||||
import TextShow (toText)
|
import TextShow (toText)
|
||||||
import Text.XML.HXT.DOM.Util (hexStringToInt, intToHexString, decimalStringToInt)
|
import Text.XML.HXT.DOM.Util (hexStringToInt, intToHexString, decimalStringToInt)
|
||||||
import TextShow.Data.Integral (showbBin, showbOct)
|
import TextShow.Data.Integral (showbBin, showbOct)
|
||||||
|
@ -196,6 +198,9 @@ dec62 input =
|
||||||
enc62 :: String -> String
|
enc62 :: String -> String
|
||||||
enc62 = C.unpack . BSU.fromString. Latin1.toString . (Bytes.fromByteArray . ( B62.encode64 . (intToWord64 . decimalStringToInt)))
|
enc62 = C.unpack . BSU.fromString. Latin1.toString . (Bytes.fromByteArray . ( B62.encode64 . (intToWord64 . decimalStringToInt)))
|
||||||
|
|
||||||
|
-- enc62 :: Text -> Text
|
||||||
|
-- enc62 text = B62.text128 (fromIntegral (T.length text))
|
||||||
|
|
||||||
dec58 :: String -> String
|
dec58 :: String -> String
|
||||||
-- dec58 = C.unpack . fromJust . B58.decodeBase58 . pack
|
-- dec58 = C.unpack . fromJust . B58.decodeBase58 . pack
|
||||||
dec58 input =
|
dec58 input =
|
||||||
|
@ -288,6 +293,8 @@ base64Regex = "^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$"
|
||||||
base58Regex = "^[1-9A-HJ-NP-Za-km-z]+$" -- incorrect
|
base58Regex = "^[1-9A-HJ-NP-Za-km-z]+$" -- incorrect
|
||||||
base32Regex = "^(?:[A-Z2-7]{8})*(?:[A-Z2-7]{2}={6}|[A-Z2-7]{4}={4}|[A-Z2-7]{5}={3}|[A-Z2-7]{7}=)?$"
|
base32Regex = "^(?:[A-Z2-7]{8})*(?:[A-Z2-7]{2}={6}|[A-Z2-7]{4}={4}|[A-Z2-7]{5}={3}|[A-Z2-7]{7}=)?$"
|
||||||
base16Regex = "^[0-9A-FXx]*$"
|
base16Regex = "^[0-9A-FXx]*$"
|
||||||
|
base10Regex = "^[0-9]*$"
|
||||||
|
base8Regex = "^[0-7]*$"
|
||||||
base2Regex = "^[01]*$"
|
base2Regex = "^[01]*$"
|
||||||
urlRegex = "^[a-zA-Z0-9%]*$"
|
urlRegex = "^[a-zA-Z0-9%]*$"
|
||||||
|
|
||||||
|
@ -299,6 +306,8 @@ solveEnc input =
|
||||||
isBase58 = BSU.fromString input =~ base58Regex :: Bool
|
isBase58 = BSU.fromString input =~ base58Regex :: Bool
|
||||||
isBase32 = BSU.fromString input =~ base32Regex :: Bool
|
isBase32 = BSU.fromString input =~ base32Regex :: Bool
|
||||||
isBase16 = BSU.fromString input =~ base16Regex :: Bool
|
isBase16 = BSU.fromString input =~ base16Regex :: Bool
|
||||||
|
isBase10 = BSU.fromString input =~ base10Regex :: Bool
|
||||||
|
isBase8 = BSU.fromString input =~ base8Regex :: Bool
|
||||||
isBase2 = BSU.fromString input =~ base2Regex :: Bool
|
isBase2 = BSU.fromString input =~ base2Regex :: Bool
|
||||||
isURL = BSU.fromString input =~ urlRegex :: Bool
|
isURL = BSU.fromString input =~ urlRegex :: Bool
|
||||||
base91Result = if isBase91 then "\nTrying base91:\n" ++ dec91 input else ""
|
base91Result = if isBase91 then "\nTrying base91:\n" ++ dec91 input else ""
|
||||||
|
@ -307,9 +316,11 @@ solveEnc input =
|
||||||
base58Result = if isBase58 then "\nTrying base58:\n" ++ dec58 input else ""
|
base58Result = if isBase58 then "\nTrying base58:\n" ++ dec58 input else ""
|
||||||
base32Result = if isBase64 then "\nTrying base32:\n" ++ dec32 input else ""
|
base32Result = if isBase64 then "\nTrying base32:\n" ++ dec32 input else ""
|
||||||
base16Result = if isBase16 then "\nTrying base16:\n" ++ dec16 input else ""
|
base16Result = if isBase16 then "\nTrying base16:\n" ++ dec16 input else ""
|
||||||
|
base10Result = if isBase10 then "\nTrying base10:\n" ++ dec10 input else ""
|
||||||
base2Result = if isBase2 then "\nTrying base2:\n" ++ dec2 input else ""
|
base2Result = if isBase2 then "\nTrying base2:\n" ++ dec2 input else ""
|
||||||
|
base8Result = if isBase8 then "\nTrying base8:\n" ++ dec8 input else ""
|
||||||
urlResult = if isURL then "\nTrying URL decode:\n" ++ decurl input else ""
|
urlResult = if isURL then "\nTrying URL decode:\n" ++ decurl input else ""
|
||||||
results = filter (not . null) [base91Result, base85Result, base64Result, base58Result, base32Result, base16Result, base2Result, urlResult]
|
results = filter (not . null) [base91Result, base85Result, base64Result, base58Result, base32Result, base16Result, base10Result, base8Result, base2Result, urlResult]
|
||||||
in
|
in
|
||||||
if null results
|
if null results
|
||||||
then "Not able to solve the encoding.\n"
|
then "Not able to solve the encoding.\n"
|
||||||
|
@ -327,6 +338,7 @@ solveEnc input =
|
||||||
-- then dec32 input
|
-- then dec32 input
|
||||||
-- else "Not able to solve the encoding.\n"
|
-- else "Not able to solve the encoding.\n"
|
||||||
|
|
||||||
|
-- optionHandler :: EncodeOptions -> Text -> Text
|
||||||
optionHandler Decode{b91=True} = dec91
|
optionHandler Decode{b91=True} = dec91
|
||||||
optionHandler Encode{b91=True} = enc91
|
optionHandler Encode{b91=True} = enc91
|
||||||
optionHandler Decode{b85=True} = dec85
|
optionHandler Decode{b85=True} = dec85
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
./dist-newstyle/build/aarch64-linux/ghc-9.4.8/based-0.4.2.0/x/based/build/based/based
|
Loading…
Reference in New Issue