Skip to content

Commit

Permalink
πŸ“… Commit Wed, 11 Aug 2021 19:07:06
Browse files Browse the repository at this point in the history
✨ Makefile to run tests
✨ strip method. Similar find_replace
πŸ› fix logic with word seperator in morse decode
🎨 rename split to split_by_char
  • Loading branch information
securisec committed Aug 11, 2021
1 parent c2ab66d commit 15546e6
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 13 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.PHONY: test test-report

test:
pytest --cov-report term-missing --cov=chepy tests

test-report:
pytest --disable-pytest-warnings --cov-report=xml --cov=chepy --cov-config=.coveragerc tests/
10 changes: 6 additions & 4 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ New ideas:
☐ save registers https://t.co/pBNRufibY8?amp=1
☐ cbor encode/decode https://github.com/agronholm/cbor2 (plugin)
☐ fuzzy search
βœ” ecc generate
☐ pgp, generate, encrypt, decrypt, verify
☐ swap little and big endian

Bug:

Cli:
☐ optionally show output window in a split screen window
☐ lower the chepy prompt lower. that empty space is not being used
Expand All @@ -32,9 +33,6 @@ Methods:
☐ base 92

Github Actions:
☐ build pyinstaller artifact for osx
☐ build pyinstaller artifact for linux
☐ build pyinstaller artifact for windows

Distribution:
☐ request to add to kali
Expand All @@ -46,6 +44,10 @@ Misc:
☐ cyberchef recipe to chepy recipe converter

Archive:
βœ” build pyinstaller artifact for osx, linux, windows @project(Github Actions)
βœ” @high from morse word delimiter is broken - .... . / ..-. .-.. .- --. / .. ... / --- .--- --.- -..- . -.-- ...-- ..- -- --.. ..... .-- .. -- .-.. . .-.. ..... ....- - .- ..... -.- --... --- .- --.. - --. ..--- ..--- --... --. -... --.. ..-. -.... -. .-.. --.- .--. . --... - -.... .--. --.. --... .-.. ..... - --. -.-. -. -.. -... -- -- ...-- -.. .- -. .-.. ..... / -... .- ... . ...-- ..--- @project(Bug)
βœ” ecc generate @project(New ideas)
βœ” strip/replace method @project(New ideas)
βœ” convert to nato alphabets: a = alpha, b = bravo @project(New ideas)
βœ” rsa sign/verify @project(New ideas)
βœ” rsa generate random key (private and public) @project(New ideas)
Expand Down
9 changes: 5 additions & 4 deletions chepy/modules/encryptionencoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,14 +1011,13 @@ def from_morse_code(
morse_code_dict[k] = v.replace(".", dot).replace("-", dash)

morse_code_dict = {value: key for key, value in morse_code_dict.items()}

for chars in self._convert_to_str().split(letter_delim):
if word_delim in chars:
print("here", chars)
chars = re.sub(word_delim, "", chars, re.I)
print(chars)
if morse_code_dict.get(chars) is not None:
decode += " " + morse_code_dict.get(chars)
else: # pragma: no cover
decode += " " + chars
else:
decode += morse_code_dict.get(chars)
self.state = decode
Expand Down Expand Up @@ -1076,7 +1075,9 @@ def rsa_sign(self, priv_key_path: str) -> EncryptionEncodingT:
return self

@ChepyDecorators.call_stack
def rsa_verify(self, signature: bytes, public_key_path: str) -> EncryptionEncodingT: # pragma: no cover
def rsa_verify(
self, signature: bytes, public_key_path: str
) -> EncryptionEncodingT: # pragma: no cover
"""Verify data in state with RSA Public key in PEM format
Args:
Expand Down
23 changes: 22 additions & 1 deletion chepy/modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def regex_search(
return self

@ChepyDecorators.call_stack
def split(self, delimiter: str = " ") -> UtilsT:
def split_by_char(self, delimiter: str = " ") -> UtilsT:
"""Split a string by a delimiter
Args:
Expand Down Expand Up @@ -415,6 +415,27 @@ def slice(self, start: int = 0, end: int = None) -> UtilsT:
self.state = self.state[start:end]
return self

@ChepyDecorators.call_stack
def strip(self, pattern: str, ignore_case=True) -> UtilsT:
"""Strip matched pattern
Args:
pattern (str): Required. Pattern to search
ignore_case (bool, optional): Case insensitive. Defaults to True.
Returns:
Chepy: The Chepy object.
Examples:
>>> Chepy("some some data").strip(r"some\s").o
"data"
"""
flags = 0
if ignore_case:
flags = re.IGNORECASE
self.state = re.sub(pattern, "", self._convert_to_str(), flags=flags)
return self

@ChepyDecorators.call_stack
def find_replace(self, pattern: str, repl: str, ignore_case=True) -> UtilsT:
"""Replace matched pattern with repln
Expand Down
3 changes: 2 additions & 1 deletion chepy/modules/utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Utils(ChepyCore):
def remove_whitespace(self: UtilsT, spaces: bool=..., carriage_return: bool=..., line_feeds: bool=..., tabs: bool=..., form_feeds: bool=...) -> Any: ...
def remove_nullbytes(self: UtilsT) -> UtilsT: ...
def regex_search(self: UtilsT, pattern: str, ignore_case: bool=..., multiline: bool=..., dotall: bool=..., unicode: bool=..., extended: bool=...) -> Any: ...
def split(self: UtilsT, delimiter: str=...) -> UtilsT: ...
def split_by_char(self: UtilsT, delimiter: str=...) -> UtilsT: ...
def split_by_regex(self: UtilsT, pattern: str=..., trim: Any=...) -> UtilsT: ...
def split_by_n(self: UtilsT, n: int) -> UtilsT: ...
def select_every_n(self: UtilsT, n: int, start: int=...) -> UtilsT: ...
Expand All @@ -24,6 +24,7 @@ class Utils(ChepyCore):
def filter_dict_key(self: UtilsT, by: str) -> UtilsT: ...
def filter_dict_value(self: UtilsT, by: str) -> UtilsT: ...
def slice(self: UtilsT, start: int=..., end: int=...) -> UtilsT: ...
def strip(self: UtilsT, pattern: str, ignore_case: Any=...) -> UtilsT: ...
def find_replace(self: UtilsT, pattern: str, repl: str, ignore_case: Any=...) -> UtilsT: ...
def escape_string(self: UtilsT) -> UtilsT: ...
def unescape_string(self: UtilsT) -> UtilsT: ...
Expand Down
15 changes: 12 additions & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ def test_remove_nullbytes():
)


def test_split_by():
def test_split_by_char():
assert len(Chepy("some lol random lolol data").split_by_char("lo").o) == 4


def test_split_by_regex():
assert len(Chepy("some lol random lolol data").split_by_regex("lo").o) == 4
assert len(Chepy("some lol random lolol data").split_by_regex("lo", trim=False).o) == 4
assert (
len(Chepy("some lol random lolol data").split_by_regex("lo", trim=False).o) == 4
)


def test_split_by_n():
Expand Down Expand Up @@ -143,6 +149,10 @@ def test_slice():
assert Chepy("some data").slice(3, 6).o == "e d"


def test_strip():
assert Chepy("some some data").strip(r"some\s").o == "data"


def test_find_replace():
assert Chepy("some some data").find_replace(r"some\s", "data").o == "datadatadata"

Expand Down Expand Up @@ -195,4 +205,3 @@ def test_filter_list_by_length():
def test_regex_to_str():
assert len(Chepy("lol([a-c])").regex_to_str().o) == 4
assert len(Chepy("lol([a-c])").regex_to_str(all_combo=True).o) == 3

0 comments on commit 15546e6

Please sign in to comment.