Skip to content

Commit

Permalink
πŸ—“ Jul 23, 2022 11:55:57 PM
Browse files Browse the repository at this point in the history
πŸ’š build steps added/updated
✨ translate method
πŸ“” docs added/updated
πŸ§ͺ tests added/updated
  • Loading branch information
securisec committed Jul 24, 2022
1 parent e0694e0 commit 0f09430
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 20 deletions.
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.PHONY: test test-report
.PHONY: test test-all


test:
pytest --cov-report term-missing --cov=chepy tests
pytest --disable-pytest-warnings --cov-report=xml --cov=chepy --cov-config=.coveragerc tests/

test-report:
pytest --disable-pytest-warnings --cov-report=xml --cov=chepy --cov-config=.coveragerc tests/
test-all: test
pytest --disable-pytest-warnings tests_plugins/
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Misc:
☐ cyberchef recipe to chepy recipe converter

Archive:
βœ” translate function that takes a string the converts the state @project(New ideas)
βœ” split by newline @project(New ideas)
βœ” string to leetcode @project(New ideas)

17 changes: 17 additions & 0 deletions chepy/modules/dataformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1151,3 +1151,20 @@ def change(c):
hold += change(s)
self.state = hold
return self

@ChepyDecorators.call_stack
def translate(self, x: str, y: str) -> DataFormatT:
"""Replace a subset of specified characters in the state.
Args:
x (str): Chars to replace
y (str): Chars to replace with
Returns:
Chepy: The Chepy object.
"""
assert len(x) == len(y), "x and y chars are not of equal length"
s = self._convert_to_str()
o = s.maketrans(x, y)
self.state = s.translate(o)
return self
1 change: 1 addition & 0 deletions chepy/modules/dataformat.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@ class DataFormat(ChepyCore):
def select(self: DataFormatT, start: int, end: int) -> DataFormatT: ...
def length(self: DataFormatT) -> DataFormatT: ...
def to_leetcode(self: DataFormatT, replace_space: str=...) -> DataFormatT: ...
def translate(self: DataFormatT, x: str=..., y: str=...) -> DataFormatT: ...
15 changes: 0 additions & 15 deletions chepy/modules/encryptionencoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,21 +166,6 @@ def xor(
) -> EncryptionEncodingT:
"""XOR state with a key
Valid key formats are utf, hex and base64. Simple XOR cipher is a type
of additive cipher based on logical operation xor, which operates according
to the following principles.
(A * B) + (!A * !B)
A B A XOR B
0 0 0
1 0 1
0 1 1
1 1 0
The main advantage of xor chipher is that the encyption is reversible with t
he same logical operation.
Args:
key (str): Required. The key to xor by
key_type (str, optional): The key type. Valid values are hex, utf and base64. Defaults to "hex".
Expand Down
2 changes: 1 addition & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def test_load_file_binary():


def test_show_recipe():
assert Chepy("4142").from_hex()._stack == [{"function": "from_hex", "args": {}}]
assert Chepy("4142").from_hex().show_recipe() == [{"function": "from_hex", "args": {}}]


def test_run_recipe():
Expand Down
12 changes: 12 additions & 0 deletions tests/test_dataformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,15 @@ def test_length():

def test_leetcode():
assert len(Chepy("ab@ cd").to_leetcode(replace_space="_").o) == 6


def test_translate():
assert (
Chepy("synt{q41q8pq98s00o204r9800998rps8427r}")
.translate(
"NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
)
.o
== "flag{d41d8cd98f00b204e9800998ecf8427e}"
)

0 comments on commit 0f09430

Please sign in to comment.