Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tap Code Decoder #458

Merged
merged 4 commits into from Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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