Compare commits

..

No commits in common. "master" and "v0.4.5" have entirely different histories.

6 changed files with 0 additions and 133 deletions

View File

@ -1,13 +1,5 @@
Revision history for based Revision history for based
0.4.5.0 -- 2024-09-25
Added tap code
Removed some bugs of the solve functions
Added bindings for morse code, bug fix
Simplified functions, ignore non ascii characters
Added test for rotate function and yencode/decode
0.4.4.0 -- 2024-06-09 0.4.4.0 -- 2024-06-09
Added tests for every encode function included Added tests for every encode function included

View File

@ -1,53 +0,0 @@
.DEFAULT_GOAL := build
PACKAGE_NAME := based
CABAL := cabal
BUILD_FLAGS := --builddir=dist-newstyle
BUILD_DEV_FLAGS := --enable-tests --enable-benchmarks
# STATIC_FLAGS := --ghc-options="-optl-static"
STATIC_FLAGS := --enable-executable-static -O2
STRIP := strip
STRIP_FLAGS := --strip-all
INSTALL_DIR := /usr/local/bin
INSTALL_FLAGS := --overwrite-policy=always
BIN_NAME := $(PACKAGE_NAME)
.PHONY: test
build:
$(CABAL) v2-build $(BUILD_FLAGS)
static-build:
$(CABAL) v2-build $(BUILD_FLAGS) $(STATIC_FLAGS)
dev-build:
$(CABAL) v2-build $(BUILD_FLAGS) $(BUILD_DEV_FLAGS)
strip:
$(STRIP) $(STRIP_FLAGS) $(realpath $(which $(PACKAGE_NAME)))
user-install:
$(CABAL) v2-install $(BUILD_FLAGS) $(INSTALL_FLAGS)
$(STRIP) $(STRIP_FLAGS) $(realpath $(which $(PACKAGE_NAME)))
install: user-install
install -m 755 $(shell cabal v2-exec which $(BIN_NAME)) $(INSTALL_DIR)/$(BIN_NAME)
$(STRIP) $(STRIP_FLAGS) $(realpath $(which $(PACKAGE_NAME)))
echo "$(BIN_NAME) installed to $(INSTALL_DIR)"
static-install: static-build user-install
install -m 755 $(shell cabal v2-exec which $(BIN_NAME)) $(INSTALL_DIR)/$(BIN_NAME)
$(STRIP) $(STRIP_FLAGS) $(realpath $(which $(PACKAGE_NAME)))
echo "$(BIN_NAME) installed to $(INSTALL_DIR)"
test:
$(CABAL) v2-test $(BUILD_FLAGS)
clean-artifacts:
$(CABAL) v2-clean
clean: clean-artifacts
rm -f $(INSTALL_DIR)/$(BIN_NAME) \
&& echo "$(BIN_NAME) removed from $(INSTALL_DIR)" \
|| echo "$(BIN_NAME) cannot be found in $(INSTALL_DIR)"

View File

@ -5,7 +5,6 @@
module Main where module Main where
import System.Console.CmdArgs import System.Console.CmdArgs
import qualified Data.ByteString as B import qualified Data.ByteString as B
import Encoding.Unary (encunary, decunary)
import Encoding.Base2 (enc2, dec2) import Encoding.Base2 (enc2, dec2)
import Encoding.Base8 (enc8, dec8) import Encoding.Base8 (enc8, dec8)
import Encoding.Base10 (enc10, dec10) import Encoding.Base10 (enc10, dec10)
@ -43,7 +42,6 @@ data Based = Decode {
b10 :: Bool, b10 :: Bool,
b8 :: Bool, b8 :: Bool,
b2 :: Bool, b2 :: Bool,
unary :: Bool,
qp :: Bool, qp :: Bool,
uu :: Bool, uu :: Bool,
xx :: Bool, xx :: Bool,
@ -68,7 +66,6 @@ data Based = Decode {
b10 :: Bool, b10 :: Bool,
b8 :: Bool, b8 :: Bool,
b2 :: Bool, b2 :: Bool,
unary :: Bool,
qp :: Bool, qp :: Bool,
uu :: Bool, uu :: Bool,
xx :: Bool, xx :: Bool,
@ -108,8 +105,6 @@ optionHandler Decode{b8=True} = dec8
optionHandler Encode{b8=True} = enc8 optionHandler Encode{b8=True} = enc8
optionHandler Decode{b2=True} = dec2 optionHandler Decode{b2=True} = dec2
optionHandler Encode{b2=True} = enc2 optionHandler Encode{b2=True} = enc2
optionHandler Decode{unary=True} = decunary
optionHandler Encode{unary=True} = encunary
optionHandler Decode{qp=True} = decqp optionHandler Decode{qp=True} = decqp
optionHandler Encode{qp=True} = encqp optionHandler Encode{qp=True} = encqp
optionHandler Encode{uu=True} = encuu optionHandler Encode{uu=True} = encuu
@ -143,7 +138,6 @@ decodeMode = Decode {
b10 = def &= help "decode decimal", b10 = def &= help "decode decimal",
b8 = def &= help "decode octal", b8 = def &= help "decode octal",
b2 = def &= help "decode base2", b2 = def &= help "decode base2",
unary = def &= help "decode unary (8 bit) a.k.a. Chuck Norris",
qp = def &= help "decode quoted-printable", qp = def &= help "decode quoted-printable",
uu = def &= help "decode UnixToUnix", uu = def &= help "decode UnixToUnix",
xx = def &= help "decode xx, without padding", xx = def &= help "decode xx, without padding",
@ -170,7 +164,6 @@ encodeMode = Encode {
b10 = def &= help "encode decimal", b10 = def &= help "encode decimal",
b8 = def &= help "encode octal", b8 = def &= help "encode octal",
b2 = def &= help "encode base2", b2 = def &= help "encode base2",
unary = def &= help "encode unary (8 bit) a.k.a. Chuck Norris",
qp = def &= help "encode quoted-printable", qp = def &= help "encode quoted-printable",
uu = def &= help "encode UnixToUnix", uu = def &= help "encode UnixToUnix",
xx = def &= help "encode xx, without padding", xx = def &= help "encode xx, without padding",

View File

@ -8,7 +8,6 @@ author: Stefan Friese
library library
hs-source-dirs: src hs-source-dirs: src
exposed-modules: exposed-modules:
Encoding.Unary
Encoding.Base2 Encoding.Base2
Encoding.Base8 Encoding.Base8
Encoding.Base10 Encoding.Base10

View File

@ -31,7 +31,6 @@
module Encoding.Base2 module Encoding.Base2
( enc2 ( enc2
, dec2 , dec2
, binaryToChar
) where ) where
import Data.Char (ord, chr, digitToInt, intToDigit) import Data.Char (ord, chr, digitToInt, intToDigit)

View File

@ -1,63 +0,0 @@
module Encoding.Unary
( encunary
, decunary
) where
import Data.ByteString (ByteString)
import Data.List (group)
import qualified Data.ByteString.Char8 as BC
import Encoding.Base2 (dec2, enc2, binaryToChar)
import Debug.Trace (trace)
encodeChuckNorris :: ByteString -> ByteString
encodeChuckNorris binary =
let cleanBinary = BC.filter (/= ' ') binary
in BC.unwords . concatMap encodeRunLength . group $ BC.unpack cleanBinary
where
encodeRunLength :: String -> [ByteString]
encodeRunLength xs@(x:_) = [prefix x, BC.pack (replicate (length xs) '0')]
encodeRunLength [] = []
prefix '0' = BC.pack "00"
prefix '1' = BC.pack "0"
prefix c = error $ "Invalid binary character encoding" ++ show c
pairs :: [a] -> [(a, a)]
pairs (x:y:rest) = (x, y) : pairs rest
pairs _ = []
encunary :: ByteString -> ByteString
encunary input = encodeChuckNorris $ enc2 input
decodeChuckNorris :: ByteString -> ByteString
decodeChuckNorris encoded = BC.pack . concatMap (BC.unpack . decodeRunLength) . pairs . BC.words $ encoded
where
decodeRunLength :: (ByteString, ByteString) -> ByteString
decodeRunLength (prefix, zeros)
| prefix == BC.pack "00" = BC.replicate (BC.length zeros) '0'
| prefix == BC.pack "0" = BC.replicate (BC.length zeros) '1'
| otherwise = error "Invalid Unary encoding"
-- pairs (x:y:rest) = (x, y) : pairs rest
-- pairs _ = []
-- decodeRunLength ("00", zeros) = replicate (BC.length zeros) '0'
-- decodeRunLength ("0", zeros) = replicate (BC.length zeros) '1'
-- decodeRunLength _ = error "Invalid Unary encoding"
decunary :: ByteString -> ByteString
decunary encoded =
let binaryStr = decodeChuckNorris encoded
in BC.pack $ map binaryToChar (chunkBinaryString binaryStr)
where
chunkBinaryString :: ByteString -> [ByteString]
chunkBinaryString bs
| BC.null bs = []
| otherwise = let (chunk, rest) = BC.splitAt 8 bs
in chunk : chunkBinaryString rest
-- encunary input =
-- let binaryStr = enc2 input
-- in trace (show binaryStr) $ encodeChuckNorris binaryStr
-- decunary :: ByteString -> ByteString
-- decunary encoded = dec2 $ decodeChuckNorris encoded