Skip to content

Commit

Permalink
🗓 Apr 16, 2023 8:43:58 PM
Browse files Browse the repository at this point in the history
✨ from_nate
🔥 convert_to_nato renamed to to_nato
🧪 tests added/updated
  • Loading branch information
securisec committed Apr 17, 2023
1 parent 737f27d commit 89713c4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
4 changes: 4 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ New ideas:
☐ us-ascii 7bit 20127 https://gchq.github.io/CyberChef/#recipe=Encode_text('US-ASCII%20(7-bit)%20(20127)') 걳걵걮걻걢갴걳갳걟갱갲갸걟갱갵걟걢갱건걟걲갳걭갴거거갱걮걧걽
☐ vigenere make aware of all cases/numbers/specials. i.e. npcdhzaon{a4Rmp!_K1N5q0p_4vQfKkT1uA3R} key victory shaktictf{y4Yyy!_M1S5i0n_4cCoMpL1sH3D}
☐ ascii shift cipher kqfl ? snyjHYK"8fwymdxf~xdm8qq5$ = niteCTF{3arth_says_h3ll0} somewhat
☐ ✨ affine bruteforce
☐ ✨ zero-width encode/decode
☐ ✨ hill cipher encode/decode/brute

Bug:

Expand Down Expand Up @@ -59,6 +62,7 @@ Misc:
☐ cyberchef recipe to chepy recipe converter

Archive:
✔ ✨ from nato
✔ for join_by handle int
✔ ip from int and vice versa @project(New ideas)
✔ subsection. regex select from state and run all subsequent operations on the selected data @project(New ideas)
Expand Down
18 changes: 17 additions & 1 deletion chepy/modules/dataformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ def trim(self) -> DataFormatT:
return self

@ChepyDecorators.call_stack
def convert_to_nato(self, join_by: str = " ") -> DataFormatT:
def to_nato(self, join_by: str = " ") -> DataFormatT:
"""Convert string to NATO phonetic format.
Example: abc = Alpha Bravo Charlie
Expand All @@ -1206,6 +1206,22 @@ def convert_to_nato(self, join_by: str = " ") -> DataFormatT:
self.state = join_by.join(hold)
return self

@ChepyDecorators.call_stack
def from_nato(self, delimiter: str = " ", join_by: str = "") -> DataFormatT:
"""Translate NATO phoentic to words
Args:
delimiter (str, optional): Delimiter to split on. Defaults to ' '.
join_by (str, optional): Join result by. Defaults to ''.
Returns:
Chepy: The Chepy object
"""
data = self._convert_to_str().split(delimiter)
d = {v: k for k, v in Encoding.NATO_CONSTANTS_DICT.items()}
self.state = join_by.join([d.get(p, "") for p in data])
return self

@ChepyDecorators.call_stack
def swap_strings(self, by: int) -> DataFormatT:
"""Swap characters in string
Expand Down
3 changes: 2 additions & 1 deletion chepy/modules/dataformat.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class DataFormat(ChepyCore):
def to_braille(self: DataFormatT) -> DataFormatT: ...
def from_braille(self: DataFormatT) -> DataFormatT: ...
def trim(self: DataFormatT) -> DataFormatT: ...
def convert_to_nato(self: DataFormatT, join_by:str) -> DataFormatT: ...
def to_nato(self: DataFormatT, join_by:str=...) -> DataFormatT: ...
def from_nato(self: DataFormatT, delimiter: str=..., join_by: str=...) -> DataFormatT: ...
def swap_strings(self: DataFormatT, by:int) -> DataFormatT: ...
def to_string(self: DataFormatT) -> DataFormatT: ...
def select(self: DataFormatT, start: int, end: int) -> DataFormatT: ...
Expand Down
8 changes: 7 additions & 1 deletion tests/test_dataformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,13 @@ def test_from_hexdump():


def test_nato_convert():
assert Chepy("abc:1").convert_to_nato().o == "Alpha Bravo Charlie : 1"
assert Chepy("abc:1").to_nato().o == "Alpha Bravo Charlie : 1"
assert (
Chepy("Lima Alpha Kilo Echo Mike India Charlie Hotel India Golf Alpha November")
.from_nato()
.o
== "LAKEMICHIGAN"
)


def test_swap_strings():
Expand Down

0 comments on commit 89713c4

Please sign in to comment.