Compare commits
No commits in common. "6213a4a2212b6f502d0ec37e94eab8b19c069f9c" and "b60acf2008f8a4f4503066afade300e9c68209eb" have entirely different histories.
6213a4a221
...
b60acf2008
|
@ -24,7 +24,6 @@ import Encoding.Yenc (ency, decy)
|
||||||
import Encoding.LetterToNumber (encltn, decltn)
|
import Encoding.LetterToNumber (encltn, decltn)
|
||||||
import Encoding.Rotate (rotate)
|
import Encoding.Rotate (rotate)
|
||||||
import Encoding.Morse (encmorse, decmorse)
|
import Encoding.Morse (encmorse, decmorse)
|
||||||
import Encoding.Tap (enctap, dectap)
|
|
||||||
import Encoding.Solve (solveEnc)
|
import Encoding.Solve (solveEnc)
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,7 +48,6 @@ data Based = Decode {
|
||||||
a1z26 :: Bool,
|
a1z26 :: Bool,
|
||||||
rot :: Maybe Int,
|
rot :: Maybe Int,
|
||||||
morse :: Bool,
|
morse :: Bool,
|
||||||
tap :: Bool,
|
|
||||||
solve :: Bool
|
solve :: Bool
|
||||||
}
|
}
|
||||||
| Encode {
|
| Encode {
|
||||||
|
@ -72,7 +70,6 @@ data Based = Decode {
|
||||||
yenc :: Bool,
|
yenc :: Bool,
|
||||||
a1z26 :: Bool,
|
a1z26 :: Bool,
|
||||||
morse :: Bool,
|
morse :: Bool,
|
||||||
tap :: Bool,
|
|
||||||
rot :: Maybe Int
|
rot :: Maybe Int
|
||||||
}
|
}
|
||||||
deriving(Show, Data, Typeable)
|
deriving(Show, Data, Typeable)
|
||||||
|
@ -119,8 +116,6 @@ optionHandler Decode{rot=Just n} = rotate n
|
||||||
optionHandler Encode{rot=Just n} = rotate n
|
optionHandler Encode{rot=Just n} = rotate n
|
||||||
optionHandler Decode{morse=True} = decmorse
|
optionHandler Decode{morse=True} = decmorse
|
||||||
optionHandler Encode{morse=True} = encmorse
|
optionHandler Encode{morse=True} = encmorse
|
||||||
optionHandler Decode{tap=True} = dectap
|
|
||||||
optionHandler Encode{tap=True} = enctap
|
|
||||||
optionHandler Decode{solve=True} = solveEnc
|
optionHandler Decode{solve=True} = solveEnc
|
||||||
|
|
||||||
decodeMode :: Based
|
decodeMode :: Based
|
||||||
|
@ -145,7 +140,6 @@ decodeMode = Decode {
|
||||||
a1z26 = def &= help "decode letter to number",
|
a1z26 = def &= help "decode letter to number",
|
||||||
rot = def &= help "rotate characters by n positions",
|
rot = def &= help "rotate characters by n positions",
|
||||||
morse = def &= help "decode morse",
|
morse = def &= help "decode morse",
|
||||||
tap = def &= help "decode tap code using a Polybius square (5x5 grid Latin alphabet)",
|
|
||||||
solve = def &= help "solve encoding"
|
solve = def &= help "solve encoding"
|
||||||
} &= help "Decode chosen base" &=auto
|
} &= help "Decode chosen base" &=auto
|
||||||
|
|
||||||
|
@ -170,8 +164,7 @@ encodeMode = Encode {
|
||||||
yenc = def &= help "encode yEncode",
|
yenc = def &= help "encode yEncode",
|
||||||
a1z26 = def &= help "encode letter to number",
|
a1z26 = def &= help "encode letter to number",
|
||||||
rot = def &= help "rotate characters by n positions",
|
rot = def &= help "rotate characters by n positions",
|
||||||
morse = def &= help "encode morse",
|
morse = def &= help "encode morse"
|
||||||
tap = def &= help "encode tap code using a Polybius square (5x5 grid Latin alphabet)"
|
|
||||||
} &= help "Encode chosen base"
|
} &= help "Encode chosen base"
|
||||||
|
|
||||||
main :: IO()
|
main :: IO()
|
||||||
|
|
|
@ -27,7 +27,6 @@ library
|
||||||
Encoding.Rotate
|
Encoding.Rotate
|
||||||
Encoding.LetterToNumber
|
Encoding.LetterToNumber
|
||||||
Encoding.Morse
|
Encoding.Morse
|
||||||
Encoding.Tap
|
|
||||||
Encoding.Solve
|
Encoding.Solve
|
||||||
other-modules:
|
other-modules:
|
||||||
-- Data.Bytes.Text.Ascii
|
-- Data.Bytes.Text.Ascii
|
||||||
|
@ -48,8 +47,6 @@ library
|
||||||
primitive,
|
primitive,
|
||||||
regex-tdfa,
|
regex-tdfa,
|
||||||
base64-bytestring,
|
base64-bytestring,
|
||||||
containers,
|
|
||||||
split,
|
|
||||||
MorseCode
|
MorseCode
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
|
||||||
|
|
||||||
module Encoding.Tap
|
|
||||||
( enctap
|
|
||||||
, dectap
|
|
||||||
) where
|
|
||||||
|
|
||||||
import Data.Char (isAsciiUpper, isAsciiLower, toLower, chr, ord, toUpper)
|
|
||||||
import Data.List (find)
|
|
||||||
import Data.ByteString (ByteString)
|
|
||||||
import qualified Data.ByteString.Char8 as BC
|
|
||||||
|
|
||||||
enctap :: ByteString -> ByteString
|
|
||||||
enctap = BC.concatMap encodeChar
|
|
||||||
where
|
|
||||||
encodeChar ' ' = BC.singleton ' '
|
|
||||||
encodeChar 'K' = BC.pack "22" -- Special case: 'K' is encoded as "22"
|
|
||||||
encodeChar c
|
|
||||||
| isAsciiUpper c || isAsciiLower c =
|
|
||||||
let (row, col) = positionInGrid c
|
|
||||||
in BC.pack [chr (ord '0' + row), chr (ord '0' + col)]
|
|
||||||
| otherwise = BC.empty -- Handle non-alphabet characters or errors
|
|
||||||
|
|
||||||
positionInGrid c =
|
|
||||||
let idx = ord (toUpper c) - ord 'A'
|
|
||||||
row = idx `div` 5 + 1
|
|
||||||
col = idx `mod` 5 + 1
|
|
||||||
in (row, col)
|
|
||||||
|
|
||||||
dectap :: ByteString -> ByteString
|
|
||||||
dectap = BC.concat . map decodePair . chunkPairs . BC.filter (/= ' ')
|
|
||||||
where
|
|
||||||
chunkPairs :: ByteString -> [ByteString]
|
|
||||||
chunkPairs bs
|
|
||||||
| BC.null bs = []
|
|
||||||
| otherwise = let (pair, rest) = BC.splitAt 2 bs in pair : chunkPairs rest
|
|
||||||
|
|
||||||
decodePair pair
|
|
||||||
| pair == "22" = BC.singleton 'K' -- Special case: "22" is decoded as 'K'
|
|
||||||
| BC.length pair == 2 =
|
|
||||||
let [row, col] = BC.unpack pair
|
|
||||||
rowIdx = ord row - ord '0'
|
|
||||||
colIdx = ord col - ord '0'
|
|
||||||
idx = (rowIdx - 1) * 5 + (colIdx - 1)
|
|
||||||
in BC.singleton $ chr (ord 'A' + idx)
|
|
||||||
| otherwise = error $ "Invalid Tap Code sequence: " ++ show pair
|
|
||||||
|
|
Loading…
Reference in New Issue