diff --git a/Main.hs b/Main.hs index 02f8622..d6396ca 100644 --- a/Main.hs +++ b/Main.hs @@ -213,14 +213,23 @@ dec62 input = -- maybe "Error decoding Base62.\n" show (B62.decode128 (Bytes.fromByteString (BSU.fromString input))) stringToInt :: String -> Maybe Integer -stringToInt str = readMaybe str +stringToInt = readMaybe -enc62 :: String -> String +-- enc62 :: String -> String -- enc62 = C.unpack . BSU.fromString. Latin1.toString . (Bytes.fromByteArray . ( B62.encode64 . (intToWord64 . decimalStringToInt))) -- enc62 = T.unpack . T.decodeUtf8 . BSU.fromString . Latin1.toString . (Bytes.fromByteArray . ( B62.encode64 . (intToWord64 . decimalStringToInt))) -- enc62 = T.unpack . T.decodeUtf8 . BSU.fromString . Latin1.toString . (Bytes.fromByteArray . (B62.encode128 . (fromIntegral . ( BSU.fromString . fromJust StringToInt)))) -enc62 = T.unpack . T.decodeUtf8 . BSU.fromString . Latin1.toString . Bytes.fromByteArray . B62.encode64 . fromIntegral . fromJust . stringToInt +-- working correct: +-- enc62 :: String -> String +-- enc62 = T.unpack . T.decodeUtf8 . BSU.fromString . Latin1.toString . Bytes.fromByteArray . B62.encode64 . fromIntegral . fromJust . stringToInt + +enc62 :: String -> String +enc62 input = + let intValue = fromMaybe (error "Error: Unable to convert input string to integer") (stringToInt input) + encoded = B62.encode64 (fromIntegral intValue) + encodedText = T.decodeUtf8 (BSU.fromString (Latin1.toString (Bytes.fromByteArray encoded))) + in T.unpack encodedText -- enc62 :: Text -> Text -- enc62 text = B62.text128 (fromIntegral (T.length text))