Skip to content

Commit

Permalink
🗓 Sep 29, 2024 1:04:01 AM
Browse files Browse the repository at this point in the history
🐙 minor changes
🐙 to_int to handle bytes
🧪 tests added/updated
  • Loading branch information
securisec committed Sep 29, 2024
1 parent e2a9284 commit 3b245ea
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion chepy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion chepy/modules/aritmeticlogic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions chepy/modules/codetidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions chepy/modules/dataformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,17 +459,24 @@ 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.
Examples:
>>> 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
Expand Down
2 changes: 1 addition & 1 deletion chepy/modules/dataformat.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down
18 changes: 9 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
setuptools
typing_extensions
1 change: 1 addition & 0 deletions tests/test_dataformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 3b245ea

Please sign in to comment.