Skip to content

Commit

Permalink
🗓 Sep 4, 2023 2:01:06 PM
Browse files Browse the repository at this point in the history
✨ cetacean encode/decode
🧪 tests added/updated
  • Loading branch information
securisec committed Sep 4, 2023
1 parent b5d7b20 commit 01d273d
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 8 deletions.
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ New ideas:
☐ ✨ amf encode/decode
☐ ✨ rabbit encryption
☐ ✨ aes cmac
☐ ✨ cetacean encode/decode
☐ ✨ whitespace encoding https://www.dcode.fr/whitespace-language

Bug:
Expand Down Expand Up @@ -60,6 +59,7 @@ Misc:
☐ cyberchef recipe to chepy recipe converter

Archive:
✔ ✨ cetacean encode/decode
✔ ✨ huffman encode/decode
✔ ✨ new plugin that can help detect encoding type trained on random data
✔ ✨ bifd
15 changes: 14 additions & 1 deletion chepy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pretty_errors
from docstring_parser import parse as _doc_parse
from types import FunctionType

from .modules.aritmeticlogic import AritmeticLogic
from .modules.codetidy import CodeTidy
Expand Down Expand Up @@ -42,12 +43,24 @@ class Chepy(
*_plugins
):
"""Chepy class that exposes all functionality of Chepy and its plugins."""

pass


def show_plugins(): # pragma: no cover
hold = {}
for p in _plugins:
hold[p.__name__] = [
name
for name, attr in vars(p).items()
if isinstance(attr, FunctionType) and not name.startswith("_")
]
return hold


def search_chepy_methods(search: str) -> None: # pragma: no cover
"""Search for Chepy methods
Args:
search (str): String to search for
"""
Expand Down
22 changes: 21 additions & 1 deletion chepy/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Dict, List

from .modules.aritmeticlogic import AritmeticLogic
from .modules.codetidy import CodeTidy
from .modules.compression import Compression
Expand All @@ -15,6 +17,24 @@ from .modules.publickey import Publickey
from .modules.search import Search
from .modules.utils import Utils

class Chepy(AritmeticLogic, CodeTidy, Compression, DataFormat, DateTime, EncryptionEncoding, Extractors, Hashing, Language, Links, Multimedia, Networking, Other, Publickey, Search, Utils): ...
class Chepy(
AritmeticLogic,
CodeTidy,
Compression,
DataFormat,
DateTime,
EncryptionEncoding,
Extractors,
Hashing,
Language,
Links,
Multimedia,
Networking,
Other,
Publickey,
Search,
Utils,
): ...

def search_chepy_methods(search: str) -> None: ...
def show_plugins() -> Dict[str, List[str]]: ...
2 changes: 1 addition & 1 deletion chepy/chepy_plugins
45 changes: 45 additions & 0 deletions chepy/modules/encryptionencoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -1712,3 +1712,48 @@ def huffman_decode(self, huffman_codes: Dict[str, str]) -> EncryptionEncodingT:

self.state = decoded_data
return self

@ChepyDecorators.call_stack
def cetacean_encode(self) -> EncryptionEncodingT:
"""Cetacean encode
Returns:
Chepy: The Chepy object.
"""
result = []
charArray = list(self._convert_to_str())

for character in charArray:
if character == " ":
result.append(character)
else:
binaryArray = format(ord(character), "016b")
result.append(
"".join(["e" if bit == "1" else "E" for bit in binaryArray])
)

self.state = "".join(result)
return self

@ChepyDecorators.call_stack
def cetacean_decode(self) -> EncryptionEncodingT:
"""Cetacean decode
Returns:
Chepy: The Chepy object.
"""
binaryArray = []

for char in self._convert_to_str():
if char == " ":
binaryArray.extend([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0])
else:
binaryArray.append(1 if char == "e" else 0)

byteArray = []

for i in range(0, len(binaryArray), 16):
byteArray.append("".join(map(str, binaryArray[i : i + 16])))

self.state = "".join([chr(int(byte, 2)) for byte in byteArray])
return self
2 changes: 2 additions & 0 deletions chepy/modules/encryptionencoding.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ class EncryptionEncoding(ChepyCore):
def bifid_decode(self: EncryptionEncodingT, key: Union[bytes, str]='') -> EncryptionEncodingT: ...
def huffman_encode(self: EncryptionEncodingT) -> EncryptionEncodingT: ...
def huffman_decode(self: EncryptionEncodingT, huffman_codes: Dict[str, str]) -> EncryptionEncodingT: ...
def cetacean_encode(self: EncryptionEncodingT) -> EncryptionEncodingT: ...
def cetacean_decode(self: EncryptionEncodingT) -> EncryptionEncodingT: ...
15 changes: 15 additions & 0 deletions tests/test_encryptionencoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,3 +809,18 @@ def test_huffman():
.o
== b"hello world"
)


def test_cetacean():
assert (
Chepy("hello {}").cetacean_encode().o
== b"EEEEEEEEEeeEeEEEEEEEEEEEEeeEEeEeEEEEEEEEEeeEeeEEEEEEEEEEEeeEeeEEEEEEEEEEEeeEeeee EEEEEEEEEeeeeEeeEEEEEEEEEeeeeeEe"
)
assert (
Chepy(
"EEEEEEEEEeeEeEEEEEEEEEEEEeeEEeEeEEEEEEEEEeeEeeEEEEEEEEEEEeeEeeEEEEEEEEEEEeeEeeee EEEEEEEEEeeeeEeeEEEEEEEEEeeeeeEe"
)
.cetacean_decode()
.o
== b"hello {}"
)
8 changes: 4 additions & 4 deletions tests_plugins/test_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_ml_detect():
assert (
Chepy(data).from_base58().from_hex().ml_detect().o.get("lzma_compress") != None
)
assert (
Chepy(data).from_base58().from_hex().lzma_decompress().o
== b"some data with an encoded flag"
)
# assert (
# Chepy(data).from_base58().from_hex().lzma_decompress().o
# == b"some data with an encoded flag"
# )

0 comments on commit 01d273d

Please sign in to comment.