Skip to content

Commit

Permalink
🗓 May 26, 2024 10:52:12 PM
Browse files Browse the repository at this point in the history
✨ increment/decrement bytes
✨ print method in core to print state
🤖 types added/updated
  • Loading branch information
securisec committed May 27, 2024
1 parent 5782adf commit 1dbc03b
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 7 deletions.
2 changes: 1 addition & 1 deletion chepy/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "7.0.0" # pragma: no cover
__version__ = "7.1.0" # pragma: no cover
__author__ = "@securisec" # pragma: no cover
12 changes: 11 additions & 1 deletion chepy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,16 @@ def debug(self, verbose: bool = False):
print(magenta("Buffers:"), self.buffers)
return self

@ChepyDecorators.call_stack
def print(self, *args): # pragma: no cover
"""Print the state
Returns:
Chepy: The Chepy object.
"""
print(*args, self.state)
return self

@ChepyDecorators.call_stack
def reset(self):
"""Reset states back to their initial values
Expand Down Expand Up @@ -1494,7 +1504,7 @@ def register(
Examples:
>>> c = Chepy("hello world")
>>> c.register("(hello)\s(world)")
>>> c.register(r"(hello)\s(world)")
>>> c._registers
{'$R0': 'hello', '$R1': 'world'}
"""
Expand Down
5 changes: 3 additions & 2 deletions chepy/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ class ChepyCore:
def loop_list(self: ChepyCoreT, callback: Union[str, Callable], args: dict=...) -> ChepyCoreT: ...
def loop_dict(self: ChepyCoreT, keys: list, callback: Union[str, Callable], args: dict=...) -> ChepyCoreT: ...
def debug(self: ChepyCoreT, verbose: bool=...) -> ChepyCoreT: ...
def reset(self: ChepyCoreT): ...
def load_command(self: ChepyCoreT): ...
def reset(self: ChepyCoreT) -> ChepyCoreT: ...
def print(self: ChepyCoreT) -> ChepyCoreT: ...
def load_command(self: ChepyCoreT) -> ChepyCoreT: ...
def pretty(self: ChepyCoreT, indent: int=...) -> ChepyCoreT: ...
def plugins(self: ChepyCoreT, enable: Literal['true', 'false']) -> None: ...
def set_plugin_path(self: ChepyCoreT, path: str) -> None: ...
Expand Down
40 changes: 38 additions & 2 deletions chepy/modules/dataformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2157,7 +2157,7 @@ def to_quoted_printable(self) -> DataFormatT:
return self

@ChepyDecorators.call_stack
def from_rison(self):
def from_rison(self) -> DataFormatT:
"""Encode to RISON
Returns:
Expand All @@ -2167,7 +2167,7 @@ def from_rison(self):
return self

@ChepyDecorators.call_stack
def to_rison(self):
def to_rison(self) -> DataFormatT:
"""Decode from RISON
Returns:
Expand All @@ -2184,3 +2184,39 @@ def to_rison(self):
# else:
# self._log.error('Invalid data type')
return self

@ChepyDecorators.call_stack
def increment_bytes(self, n: int) -> DataFormatT:
"""Loop through each byte and increment
Args:
n (int): increment by.
Returns:
Chepy: The Chepy object.
"""
count = int(n)
hold = bytearray()
data = self._convert_to_bytes()
for d in data:
hold.append(d + count)
self.state = bytes(hold)
return self

@ChepyDecorators.call_stack
def decrement_bytes(self, n: int) -> DataFormatT:
"""Loop through each byte and decrement
Args:
n (int): decrement by.
Returns:
Chepy: The Chepy object.
"""
count = int(n)
hold = bytearray()
data = self._convert_to_bytes()
for d in data:
hold.append(d - count)
self.state = bytes(hold)
return self
2 changes: 2 additions & 0 deletions chepy/modules/dataformat.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,5 @@ class DataFormat(ChepyCore):
def to_quoted_printable(self: DataFormatT) -> DataFormatT: ...
def from_rison(self: DataFormatT) -> DataFormatT: ...
def to_rison(self: DataFormatT) -> DataFormatT: ...
def increment_bytes(self: DataFormatT, n: int) -> DataFormatT: ...
def decrement_bytes(self: DataFormatT, n: int) -> DataFormatT: ...
1 change: 0 additions & 1 deletion chepy/modules/encryptionencoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import lazy_import

jwt = lazy_import.lazy_module("jwt")
import pathlib

import regex as re
import json
Expand Down
11 changes: 11 additions & 0 deletions tests/test_dataformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,3 +783,14 @@ def test_base92():
def test_base45():
assert Chepy("+8D VDL2").from_base45().o == b"hello"
assert Chepy("hello").to_base45().o == b"+8D VDL2"


def test_inc_dec_bytes():
assert (
Chepy("gmbh|cc265ceg113b731ec768c9eg95b98175~").decrement_bytes(1).o
== b"flag{bb154bdf002a620db657b8df84a87064}"
)
assert (
Chepy("flag{bb154bdf002a620db657b8df84a87064}").increment_bytes(1).o
== b"gmbh|cc265ceg113b731ec768c9eg95b98175~"
)

0 comments on commit 1dbc03b

Please sign in to comment.