From 3b245ea3f7609204ba3e35f84e005c36836d6fa8 Mon Sep 17 00:00:00 2001 From: securisec Date: Sun, 29 Sep 2024 01:06:01 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=93=20Sep=2029,=202024=201:04:01?= =?UTF-8?q?=E2=80=AFAM?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ๐Ÿ™ minor changes ๐Ÿ™ to_int to handle bytes ๐Ÿงช tests added/updated --- chepy/core.py | 2 +- chepy/modules/aritmeticlogic.py | 2 +- chepy/modules/codetidy.py | 5 +++-- chepy/modules/dataformat.py | 11 +++++++++-- chepy/modules/dataformat.pyi | 2 +- requirements.txt | 18 +++++++++--------- tests/test_dataformat.py | 1 + 7 files changed, 25 insertions(+), 16 deletions(-) diff --git a/chepy/core.py b/chepy/core.py index 0826e3d..3420619 100644 --- a/chepy/core.py +++ b/chepy/core.py @@ -1594,7 +1594,7 @@ def prefix(self, data: bytes): return self @ChepyDecorators.call_stack - def suffix(self, data: bytes): + def suffix(self, data: Union[str, bytes]): """Add a suffix to the data in state. The state is converted to bytes Args: diff --git a/chepy/modules/aritmeticlogic.py b/chepy/modules/aritmeticlogic.py index b672d8c..0481b3f 100644 --- a/chepy/modules/aritmeticlogic.py +++ b/chepy/modules/aritmeticlogic.py @@ -53,7 +53,7 @@ def add(self, n: int) -> AritmeticLogicT: # Convert the result back to a byte hold += result_code.to_bytes(1, byteorder="big") - self.state = hold + self.state = hold.decode() return self @ChepyDecorators.call_stack diff --git a/chepy/modules/codetidy.py b/chepy/modules/codetidy.py index fdc9f4e..5190560 100644 --- a/chepy/modules/codetidy.py +++ b/chepy/modules/codetidy.py @@ -200,8 +200,9 @@ def to_leetspeak(self, special_chars: bool = True) -> CodeTidyT: hold = "" for char in list(self._convert_to_str()): upper = char.upper() - if chars.get(upper): - hold += chars.get(upper) + char_to_append = chars.get(upper) + if char_to_append: + hold += char_to_append else: hold += char self.state = hold diff --git a/chepy/modules/dataformat.py b/chepy/modules/dataformat.py index 2143db0..b15def0 100644 --- a/chepy/modules/dataformat.py +++ b/chepy/modules/dataformat.py @@ -459,9 +459,13 @@ def from_base91(self) -> DataFormatT: # pragma: no cover return self @ChepyDecorators.call_stack - def to_int(self) -> DataFormatT: + def to_int(self, byteorder: Literal['little', 'big']='big', base:int=10) -> DataFormatT: """Converts the string representation of a number into an int + Args: + byteorder(Literal['little', 'big']): Byte order if state is bytes + base(int): If state is a str, the base to convert it to. + Returns: Chepy: The Chepy object. @@ -469,7 +473,10 @@ def to_int(self) -> DataFormatT: >>> Chepy("1").to_int().o 1 """ - self.state = int(self.state) + if isinstance(self.state, bytes): + self.state = int.from_bytes(self.state, byteorder) + elif isinstance(self.state, str): + self.state = int(self.state, base) return self @ChepyDecorators.call_stack diff --git a/chepy/modules/dataformat.pyi b/chepy/modules/dataformat.pyi index aece364..a15e310 100644 --- a/chepy/modules/dataformat.pyi +++ b/chepy/modules/dataformat.pyi @@ -25,7 +25,7 @@ class DataFormat(ChepyCore): def from_base16(self: DataFormatT) -> DataFormatT: ... def to_base32(self: DataFormatT) -> DataFormatT: ... def from_base32(self: DataFormatT, remove_whitespace: bool=True) -> DataFormatT: ... - def to_int(self: DataFormatT) -> DataFormatT: ... + def to_int(self: DataFormatT, byteorder: Literal['big', 'little']='big', base: int=10) -> DataFormatT: ... def to_bytes(self: DataFormatT) -> DataFormatT: ... def from_bytes(self: DataFormatT) -> DataFormatT: ... def to_base64(self: DataFormatT, alphabet: Literal[str, 'standard', 'url_safe', 'filename_safe', 'itoa64', 'xml', 'z64', 'radix_64', 'xxencoding', 'rot13', 'unix_crypt']='standard') -> DataFormatT: ... diff --git a/requirements.txt b/requirements.txt index d865aee..8657456 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,10 +6,15 @@ docstring-parser emoji==2.0.0 exrex fire==0.6.0 -lazy-import hexdump -jsonpickle jmespath==1.0.1 +jsonpickle +lazy-import +lz4==4.3.2 +msgpack==1.0.4 +parsel==1.9.1 +passlib==1.7.4 +pretty-errors==1.2.25 prompt_toolkit>=2.0.8 pycipher pycryptodome @@ -19,10 +24,5 @@ pyOpenSSL==23.2.0 pyperclip PyYAML regex -typing_extensions -pretty-errors==1.2.25 -lz4==4.3.2 -passlib==1.7.4 -msgpack==1.0.4 -parsel==1.8.1 -setuptools \ No newline at end of file +setuptools +typing_extensions \ No newline at end of file diff --git a/tests/test_dataformat.py b/tests/test_dataformat.py index 1c76725..76eb09f 100644 --- a/tests/test_dataformat.py +++ b/tests/test_dataformat.py @@ -241,6 +241,7 @@ def test_join(): def test_to_int(): assert Chepy("1").to_int().o == 1 + assert Chepy('AQAB').from_base64().to_int().o == 65537 def test_normalize_hex():