diff --git a/TODO b/TODO index 124da24..dacc006 100644 --- a/TODO +++ b/TODO @@ -27,7 +27,6 @@ New ideas: ☐ ✨ aes cmac ☐ ✨ whitespace encoding https://www.dcode.fr/whitespace-language ☐ beaufort - ☐ register support in callstack ☐ 🔥 update python_requires in setup.py on python version change ☐ 🐙 update config to use envars also @@ -46,19 +45,10 @@ Enhance: Plugins: -Methods: - ☐ magic method from cyberchef - ☐ base 92 - -Github Actions: - -Distribution: - ☐ request to add to kali - ☐ request to add to brew - Misc: ☐ cyberchef recipe to chepy recipe converter Archive: + ✔ register support in callstack ✔ ecb no padding in aes/des ✔ update ml model with different spacing for hex, binary etc diff --git a/chepy/core.py b/chepy/core.py index 9fa63fa..3563771 100644 --- a/chepy/core.py +++ b/chepy/core.py @@ -66,7 +66,7 @@ class ChepyCore(object): **buffers**, etc and is required to use and extend Chepy. Args: - \*data (tuple): The core class takes arbitrary number of arguments as \*args. + *data (tuple): The core class takes arbitrary number of arguments as *args. Attributes: states (dict): Contains all the current states. Each arg passed to @@ -1469,6 +1469,7 @@ def cb(data): self.state = callback_function(self.state) return self + @ChepyDecorators.call_stack def register( self, pattern: Union[str, bytes], diff --git a/chepy/modules/dataformat.py b/chepy/modules/dataformat.py index 3d8f1cf..2f2f6ed 100644 --- a/chepy/modules/dataformat.py +++ b/chepy/modules/dataformat.py @@ -321,7 +321,7 @@ def to_base32(self) -> DataFormatT: return self @ChepyDecorators.call_stack - def from_base32(self) -> DataFormatT: + def from_base32(self, remove_whitespace: bool = True) -> DataFormatT: """Decode as Base32 Base32 is a notation for encoding arbitrary byte data using a @@ -329,9 +329,14 @@ def from_base32(self) -> DataFormatT: and processed by computers. It uses a smaller set of characters than Base64, usually the uppercase alphabet and the numbers 2 to 7. + Args: + remove_whitespace(bool, optional): If true, all whitespaces are removed + Returns: Chepy: The Chepy object. """ + if remove_whitespace: + self.state = self.remove_whitespace().o self.state = base64.b32decode(self.state) return self @@ -485,7 +490,7 @@ def to_base64(self, custom: str = None, url_safe: bool = False) -> DataFormatT: return self @ChepyDecorators.call_stack - def from_base64(self, custom: str = None, url_safe: bool = False) -> DataFormatT: + def from_base64(self, custom: str = None, url_safe: bool = False, remove_whitespace: bool = True) -> DataFormatT: """Decode as Base64 Base64 is a notation for encoding arbitrary byte data using a @@ -496,6 +501,7 @@ def from_base64(self, custom: str = None, url_safe: bool = False) -> DataFormatT Args: custom (str, optional): Provide a custom charset to base64 with url_safe (bool, optional): If true, decode url safe. Defaults to False + remove_whitespace(bool, optional): If true, all whitespaces are removed Returns: Chepy: The Chepy object. @@ -507,6 +513,8 @@ def from_base64(self, custom: str = None, url_safe: bool = False) -> DataFormatT >>> c.out b"some random? data" """ + if remove_whitespace: + data = self.remove_whitespace().o data = self._convert_to_str() if custom is not None: std_base64chars = ( diff --git a/chepy/modules/dataformat.pyi b/chepy/modules/dataformat.pyi index e1e68e0..144f3e1 100644 --- a/chepy/modules/dataformat.pyi +++ b/chepy/modules/dataformat.pyi @@ -24,12 +24,12 @@ class DataFormat(ChepyCore): def to_base16(self: DataFormatT) -> DataFormatT: ... def from_base16(self: DataFormatT) -> DataFormatT: ... def to_base32(self: DataFormatT) -> DataFormatT: ... - def from_base32(self: DataFormatT) -> DataFormatT: ... + def from_base32(self: DataFormatT, remove_whitespace: bool=True) -> DataFormatT: ... def to_int(self: DataFormatT) -> DataFormatT: ... def to_bytes(self: DataFormatT) -> DataFormatT: ... def from_bytes(self: DataFormatT) -> DataFormatT: ... def to_base64(self: DataFormatT, custom: str=...) -> DataFormatT: ... - def from_base64(self: DataFormatT, custom: str=..., url_safe: bool=...) -> DataFormatT: ... + def from_base64(self: DataFormatT, custom: str=..., url_safe: bool=..., remove_whitespace: bool=True) -> DataFormatT: ... def decode_bytes(self: DataFormatT, errors: Literal['ignore', 'backslashreplace', 'replace']=...) -> DataFormatT: ... def to_hex(self: DataFormatT, delimiter: str=..., join_by: str=...) -> DataFormatT: ... def from_hex(self: DataFormatT, delimiter: Union[str, None]=None, join_by: str='') -> DataFormatT: ... diff --git a/requirements.txt b/requirements.txt index 64dd627..a82f275 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ decorator docstring-parser emoji==2.0.0 exrex -fire==0.4.0 +fire==0.6.0 lazy-import hexdump jsonpickle diff --git a/tests/test_core.py b/tests/test_core.py index f6ccf93..9125506 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -172,11 +172,9 @@ def test_run_recipe(): def test_recipe(): temp = str(Path(tempfile.gettempdir()) / os.urandom(24).hex()) - Chepy( - "tests/files/encoding" - ).load_file().reverse().rot_13().from_base64().from_base32().str_from_hexdump().save_recipe( - temp - ) + Chepy("tests/files/encoding").load_file().reverse().rot_13().from_base64( + remove_whitespace=False + ).from_base32(remove_whitespace=False).str_from_hexdump().save_recipe(temp) assert ( Chepy("tests/files/encoding").load_recipe(temp).o diff --git a/tests/test_dataformat.py b/tests/test_dataformat.py index ef0d216..fe2e600 100644 --- a/tests/test_dataformat.py +++ b/tests/test_dataformat.py @@ -104,8 +104,15 @@ def test_from_base85(): assert Chepy("F)Po,+Cno&@/").from_base85().out.decode() == "some data" -def test_to_base32(): +def test_base32(): assert Chepy("some data").to_base32().out.decode() == "ONXW2ZJAMRQXIYI=" + assert ( + Chepy("""MFWWC5DFOVZHGQ2UIZ5XA2LDGBPXONBVNY3V6ZZQGBSF63RQOVTWQXZVGBPWSXZXGAYGWX3TN5WT +GX3DOIZTI5BROYZV63BRMIZXE5BRGM2V6YLEMU4DQMRQMV6Q====""") + .from_base32() + .o + == b"amateursCTF{pic0_w45n7_g00d_n0ugh_50_i_700k_som3_cr34t1v3_l1b3rt135_ade8820e}" + ) def test_to_base64(): @@ -132,6 +139,13 @@ def test_from_base64(): == b"some random? data" ) assert Chepy("dGVzdA").from_base64(url_safe=True).o == b"test" + assert ( + Chepy("""YW1hdGV1cnNDVEZ7cGljMF93NDVuN19nMDBkX24wdWdoXzUwX2lfNzAwa19zb20zX2NyMzR0MXYz +X2wxYjNydDEzNV9hZGU4ODIwZX0=""") + .from_base64() + .o + == b"amateursCTF{pic0_w45n7_g00d_n0ugh_50_i_700k_som3_cr34t1v3_l1b3rt135_ade8820e}" + ) def test_decode_bytes(): @@ -227,7 +241,7 @@ def test_bytearray_to_str(): def test_get_by_index(): - assert Chepy([1, "a", True]).get_by_index(2).state == True + assert Chepy([1, "a", True]).get_by_index(2).state def test_get_by_key():