Skip to content

Commit

Permalink
Merge pull request #458 from Itamai/master
Browse files Browse the repository at this point in the history
Add Tap Code Decoder
  • Loading branch information
bee-san committed Oct 1, 2020
2 parents 6da0bf0 + e442451 commit a3c4d4a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions ciphey/basemods/Decoders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
baudot,
multi_tap,
url,
tap_code,
)
41 changes: 41 additions & 0 deletions ciphey/basemods/Decoders/tap_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# by https://github.com/RustyDucky and https://github.com/lukasgabriel

from typing import Optional, Dict, List

from ciphey.iface import Config, ParamSpec, T, U, Decoder, registry, Translation


@registry.register
class tap_code(Decoder[str, str]):
def decode(self, ctext: T) -> Optional[U]:
try:
output = ""
combinations = ctext.split(" ")
for fragment in combinations:
output += self.TABLE.get(fragment)
return output

except Exception as e:
return None

@staticmethod
def priority() -> float:
return 0.06

def __init__(self, config: Config):
super().__init__(config)
self.TABLE = config.get_resource(self._params()["dict"], Translation)

@staticmethod
def getParams() -> Optional[Dict[str, ParamSpec]]:
return {
"dict": ParamSpec(
desc="The table of letters used for the tap code interpretation.",
req=False,
default="cipheydists::translate::tap_code",
)
}

@staticmethod
def getTarget() -> str:
return "tap_code"
7 changes: 7 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ def test_url():
)
assert res.lower() == answer_str.lower()

def test_tap_code():
res = decrypt(
Config().library_default().complete_config(),
"4,4 1,5 4,3 4,4 3,4 3,3 1,5 4,4 5,2 3,4 4,4 2,3 4,2 1,5 1,5",
)
assert res == "test one two three".upper()

def test_brandon():
res = decrypt(
Config().library_default().complete_config(),
Expand Down

0 comments on commit a3c4d4a

Please sign in to comment.