Skip to content

Commit

Permalink
🗓 Jul 19, 2023 8:26:28 PM
Browse files Browse the repository at this point in the history
✨ windings encode/decode
✨ show warnings when cli is unpredictable
✨ contact method
🧪 tests added/updated
  • Loading branch information
securisec committed Jul 20, 2023
1 parent cab4871 commit 1f0de54
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 2 deletions.
2 changes: 2 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ New ideas:
☐ ✨ shuffle
☐ ✨ cetacean encode/decode
☐ ✨ ls47 enc/dec
☐ ✨ decorator that will show warning message if unexpected results in stdout

Bug:

Expand Down Expand Up @@ -66,6 +67,7 @@ Misc:
☐ cyberchef recipe to chepy recipe converter

Archive:
✔ ✨ concat method
✔ ✨ nt hash
✔ ✨ lm hash
✔ ✨ lz4 compression/decompression
Expand Down
8 changes: 8 additions & 0 deletions chepy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ def call_stack(func, *args, **kwargs):

return func(*args, **kwargs) # lgtm [py/call-to-non-callable]

@staticmethod
@decorator
def is_stdout(func, *args, **kwargs): # pragma: no cover
"""Detect if method is being called from the cli"""
if sys.stdout.isatty():
logging.warning(f"{func.__name__} may not work as expected on the cli")
return func(*args, **kwargs)


class ChepyCore(object):
"""The ChepyCore class for Chepy is primarily used as an interface
Expand Down
41 changes: 41 additions & 0 deletions chepy/modules/dataformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1448,3 +1448,44 @@ def bytes_to_long(self) -> DataFormatT:
d = self._convert_to_bytes()
self.state = crypto_number.bytes_to_long(d)
return self

@ChepyDecorators.call_stack
def concat(self, data: Union[str, bytes]) -> DataFormatT:
"""Concat bytes to the current state
Args:
data (Union[str, bytes]): Data to add
Returns:
Chepy: The Chepy object. s
"""
data = self._str_to_bytes(data)
self.state = self._convert_to_bytes() + data
return self

@ChepyDecorators.call_stack
def to_wingdings(self) -> DataFormatT:
"""Encode to windings
Returns:
Chepy: The Chepy object.
"""
hold = ""
for c in list(self._convert_to_str()):
hold += chr(Encoding.wingdings.get(c, ord(c)))
self.state = hold.encode()
return self

@ChepyDecorators.call_stack
def from_wingdings(self) -> DataFormatT:
"""Decode from windings
Returns:
Chepy: The Chepy object.
"""
conv = {v: k for k, v in Encoding.wingdings.items()}
hold = ""
for i in list(self._convert_to_str()):
hold += conv.get(ord(i), i)
self.state = hold.encode()
return self
3 changes: 3 additions & 0 deletions chepy/modules/dataformat.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,6 @@ class DataFormat(ChepyCore):
def bruteforce_from_base_xx(self: DataFormatT) -> DataFormatT: ...
def long_to_bytes(self: DataFormatT) -> DataFormatT: ...
def bytes_to_long(self: DataFormatT) -> DataFormatT: ...
def concat(self: DataFormatT, data: Union[str, bytes]) -> DataFormatT: ...
def to_wingdings(self) -> DataFormatT: ...
def from_wingdings(self) -> DataFormatT: ...
7 changes: 5 additions & 2 deletions chepy/modules/hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,14 +560,17 @@ def scrypt_hash(
return self

@ChepyDecorators.call_stack
@ChepyDecorators.is_stdout
def password_hashing(self, format: str, **kwargs: Any) -> HashingT:
"""Hash the state with various password hashing algorithems
Args:
format (str): Hash state with password algorithems
Returns:
Chepy: The Chepy object.
Chepy: The Chepy object.
"""
self.state = getattr(passlib.hash, format).hash(self._convert_to_bytes(), **kwargs)
self.state = getattr(passlib.hash, format).hash(
self._convert_to_bytes(), **kwargs
)
return self
98 changes: 98 additions & 0 deletions chepy/modules/internal/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,104 @@ class Encoding(object):
"⠸",
]

wingdings = {
"!": 128393,
'"': 9986,
"#": 9985,
"$": 128083,
"%": 128365,
"&": 128366,
"'": 128367,
"(": 128383,
")": 9990,
"*": 128386,
"+": 128387,
",": 128234,
"-": 128235,
".": 128236,
"/": 128237,
"0": 128193,
"1": 128194,
"2": 128196,
"3": 128463,
"4": 128464,
"5": 128452,
"6": 8987,
"7": 128430,
"8": 128432,
"9": 128434,
":": 128435,
";": 128436,
"<": 128427,
"=": 128428,
">": 9991,
"?": 9997,
"@": 128398,
"A": 9996,
"B": 128076,
"C": 128077,
"D": 128078,
"E": 9756,
"F": 9758,
"G": 9757,
"H": 9759,
"I": 128400,
"J": 9786,
"K": 128528,
"L": 9785,
"M": 128163,
"N": 9760,
"O": 127987,
"P": 127985,
"Q": 9992,
"R": 9788,
"S": 128167,
"T": 10052,
"U": 128326,
"V": 10014,
"W": 128328,
"X": 10016,
"Y": 10017,
"Z": 9770,
"[": 9775,
"\\": 2384,
"]": 9784,
"^": 9800,
"_": 9801,
"`": 9802,
"a": 9803,
"b": 9804,
"c": 9805,
"d": 9806,
"e": 9807,
"f": 9808,
"g": 9809,
"h": 9810,
"i": 9811,
"j": 128624,
"k": 128629,
"l": 9679,
"m": 128318,
"n": 9632,
"o": 9633,
"p": 128912,
"q": 10065,
"r": 10066,
"s": 11047,
"t": 10731,
"u": 9670,
"v": 10070,
"w": 11045,
"x": 8999,
"y": 11193,
"z": 8984,
"{": 10048,
"|": 127990,
"}": 10077,
"~": 128631,
" ": " ",
}


class EncryptionConsts(object):
MORSE_CODE_DICT = {
Expand Down
1 change: 1 addition & 0 deletions chepy/modules/internal/constants.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Encoding:
py_text_encodings: Any = ...
asciichars: Any = ...
brailles: Any = ...
wingdings: dict = ...
NATO_CONSTANTS_DICT: Dict[str, str] = ...
LEETCODE: List[List[str]] = ...
BASE91_ALPHABET: List[str] = ...
Expand Down
27 changes: 27 additions & 0 deletions tests/test_dataformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,3 +474,30 @@ def test_bytes_to_long():
Chepy("crypto{3nc0d1n6_4ll_7h3_w4y_d0wn}").bytes_to_long().o
== 11515195063862318899931685488813747395775516287289682636499965282714637259206269
)


def test_concat():
assert Chepy("lol").concat(b"data").o == b"loldata"
assert Chepy(["a"]).concat(b"data").o == b"['a']data"


def test_to_wingdings():
assert (
Chepy(
"f︎l︎a︎g︎{︎e︎0︎7︎9︎1︎c︎e︎6︎8︎f︎7︎1︎8︎1︎8︎8︎c︎0︎3︎7︎8︎b︎1︎c︎0︎a︎3︎b︎d︎c︎9︎e︎}︎"
)
.to_wingdings()
.o.decode()
== "♐︎●︎♋︎♑︎❀︎♏︎📁︎🖮︎🖲︎📂︎♍︎♏︎⌛︎🖰︎♐︎🖮︎📂︎🖰︎📂︎🖰︎🖰︎♍︎📁︎🗏︎🖮︎🖰︎♌︎📂︎♍︎📁︎♋︎🗏︎♌︎♎︎♍︎🖲︎♏︎❝︎"
)


def test_from_windings():
assert (
Chepy(
"♐︎●︎♋︎♑︎❀︎♏︎📁︎🖮︎🖲︎📂︎♍︎♏︎⌛︎🖰︎♐︎🖮︎📂︎🖰︎📂︎🖰︎🖰︎♍︎📁︎🗏︎🖮︎🖰︎♌︎📂︎♍︎📁︎♋︎🗏︎♌︎♎︎♍︎🖲︎♏︎❝︎"
)
.from_wingdings()
.o.decode()
== "f︎l︎a︎g︎{︎e︎0︎7︎9︎1︎c︎e︎6︎8︎f︎7︎1︎8︎1︎8︎8︎c︎0︎3︎7︎8︎b︎1︎c︎0︎a︎3︎b︎d︎c︎9︎e︎}︎"
)

0 comments on commit 1f0de54

Please sign in to comment.