Compare commits

..

2 Commits

Author SHA1 Message Date
Stefan Friese 87ccc20b85 added softlink to gitignore 2024-05-05 23:46:51 +02:00
Stefan Friese 24cbf07357 added more bases to the solver function 2024-05-05 23:45:05 +02:00
2 changed files with 16 additions and 3 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
dist-newstyle/** dist-newstyle/**
based.link

18
Main.hs
View File

@ -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 =
@ -224,7 +229,7 @@ dec16 input =
enc16 :: String -> String enc16 :: String -> String
enc16 = C.unpack . B16.encode . BSU.fromString enc16 = C.unpack . B16.encode . BSU.fromString
dec10:: String -> String dec10 :: String -> String
dec10 = show . hexStringToInt dec10 = show . hexStringToInt
enc10 :: String -> String enc10 :: String -> String
@ -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