added b91 to solver function
This commit is contained in:
parent
f21e343ef3
commit
37ee336508
35
Main.hs
35
Main.hs
|
@ -34,9 +34,13 @@ import Data.Bytes.Get (getWord64host)
|
||||||
import Data.ByteString.UTF8 as BSU -- from utf8-string
|
import Data.ByteString.UTF8 as BSU -- from utf8-string
|
||||||
-- import Data.ByteString (singleton)
|
-- import Data.ByteString (singleton)
|
||||||
import GHC.Word (Word8)
|
import GHC.Word (Word8)
|
||||||
|
-- import Data.Char
|
||||||
import qualified Data.ByteString.Char8 as C
|
import qualified Data.ByteString.Char8 as C
|
||||||
-- Regex imports
|
-- Regex imports
|
||||||
import Text.Regex.TDFA
|
import Text.Regex.TDFA
|
||||||
|
import Data.Word (Word8)
|
||||||
|
import Data.Char (ord, chr)
|
||||||
|
import Data.Maybe (fromMaybe)
|
||||||
|
|
||||||
data Based = Decode {
|
data Based = Decode {
|
||||||
b91 :: Bool,
|
b91 :: Bool,
|
||||||
|
@ -118,12 +122,26 @@ octToInt (x : xs) = x + 8 * octToInt xs
|
||||||
-- base functions
|
-- base functions
|
||||||
-- without the show func, sequences like \n will not be shown as characters but will be executed as newline
|
-- without the show func, sequences like \n will not be shown as characters but will be executed as newline
|
||||||
|
|
||||||
dec91 :: String -> String
|
-- dec91 :: String -> String
|
||||||
dec91 = C.unpack . B91.decode
|
-- dec91 = C.unpack . B91.decode
|
||||||
|
|
||||||
-- case singleton . B91.decode input of
|
dec91 :: String -> String
|
||||||
-- Right decoded -> C.unpack decoded
|
dec91 input =
|
||||||
-- Left _ -> "Error decoding Base91.\n"
|
case B91.decode input :: BSU.ByteString of
|
||||||
|
decoded -> C.unpack decoded
|
||||||
|
|
||||||
|
-- toWord8 :: String -> [Word8]
|
||||||
|
-- toWord8 = map (fromIntegral . fromEnum)
|
||||||
|
|
||||||
|
-- dec91 :: String -> String
|
||||||
|
-- dec91 input =
|
||||||
|
-- map (chr . fromIntegral) (B91.decode input :: [Word8])
|
||||||
|
|
||||||
|
-- or
|
||||||
|
-- case B91.decode input :: [Word8] of
|
||||||
|
-- Right decoded -> map (toEnum . fromIntegral) decoded
|
||||||
|
-- Left err -> "Error decoding Base91: " ++ err
|
||||||
|
|
||||||
|
|
||||||
enc91 :: String -> String
|
enc91 :: String -> String
|
||||||
enc91 = B91.encode . BSU.fromString
|
enc91 = B91.encode . BSU.fromString
|
||||||
|
@ -265,16 +283,17 @@ base16Regex = "^[0-9A-FXx]*$"
|
||||||
|
|
||||||
solveEnc :: String -> String
|
solveEnc :: String -> String
|
||||||
solveEnc input =
|
solveEnc input =
|
||||||
-- let isBase91 = BSU.fromString input =~ base91Regex :: Bool
|
let isBase91 = BSU.fromString input =~ base91Regex :: Bool
|
||||||
let isBase64 = BSU.fromString input =~ base64Regex :: Bool
|
isBase64 = BSU.fromString input =~ base64Regex :: Bool
|
||||||
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
|
||||||
|
base91Result = if isBase91 then "\nTrying base91:\n" ++ dec91 input else ""
|
||||||
base64Result = if isBase64 then "\nTrying base64:\n" ++ dec64 input else ""
|
base64Result = if isBase64 then "\nTrying base64:\n" ++ dec64 input else ""
|
||||||
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 ""
|
||||||
results = filter (not . null) [base64Result, base32Result, base16Result]
|
results = filter (not . null) [base91Result, base64Result, base32Result, base16Result]
|
||||||
in
|
in
|
||||||
if null results
|
if null results
|
||||||
then "Not able to solve the encoding.\n"
|
then "Not able to solve the encoding.\n"
|
||||||
|
|
Loading…
Reference in New Issue