Skip to content

Commit

Permalink
πŸ—“ Jun 19, 2023 11:13:25 PM
Browse files Browse the repository at this point in the history
✨ rot_47_bruteforce
πŸ”₯ update rot_47 and rename argument
πŸ§ͺ tests added/updated
  • Loading branch information
securisec committed Jun 20, 2023
1 parent cc603e7 commit 0040741
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
41 changes: 31 additions & 10 deletions chepy/modules/encryptionencoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ def rot_13(self) -> EncryptionEncodingT:
return self

@ChepyDecorators.call_stack
def rot_47(self, amount: int = 14) -> EncryptionEncodingT:
def rot_47(self, rotation: int = 47) -> EncryptionEncodingT:
"""ROT 47 encoding
A slightly more complex variation of a caesar cipher, which includes
ASCII characters from 33 '!' to 126 '~'. Default rotation: 47.
Args:
amount (int, optional): Amount to rotate by. Defaults to 14.
rotation (int, optional): Amount to rotate by. Defaults to 14.
Returns:
Chepy: The Chepy object.
Expand All @@ -166,14 +166,35 @@ def rot_47(self, amount: int = 14) -> EncryptionEncodingT:
>>> Chepy("some").rot_47().out
"D@>6"
"""
x = []
for i in range(len(self.state)):
j = ord(self.state[i])
if j >= 33 and j <= 126:
x.append(chr(33 + ((j + amount) % 94)))
else: # pragma: no cover
x.append(self.state[i])
self.state = "".join(x)
decoded_string = ''
for char in self._convert_to_str():
if ord(char) >= 33 and ord(char) <= 126:
decoded_char = chr((ord(char) - 33 + rotation) % 94 + 33)
decoded_string += decoded_char
else:
decoded_string += char
self.state = decoded_string
return self

@ChepyDecorators.call_stack
def rot_47_bruteforce(self) -> EncryptionEncodingT:
"""ROT 47 bruteforce
Returns:
Chepy: The Chepy object.
"""
hold = {}
data = self._convert_to_str()
for r in range(1, 94):
decoded_string = ''
for char in data:
if ord(char) >= 33 and ord(char) <= 126:
decoded_char = chr((ord(char) - 33 + r) % 94 + 33)
decoded_string += decoded_char
else:
decoded_string += char
hold[str(r)] = decoded_string
self.state = hold
return self

@ChepyDecorators.call_stack
Expand Down
1 change: 1 addition & 0 deletions chepy/modules/encryptionencoding.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class EncryptionEncoding(ChepyCore):
def rotate_bruteforce(self: EncryptionEncodingT) -> EncryptionEncodingT: ...
def rot_13(self: EncryptionEncodingT) -> EncryptionEncodingT: ...
def rot_47(self: EncryptionEncodingT, amount: int=...) -> EncryptionEncodingT: ...
def rot_47_bruteforce(self: EncryptionEncodingT) -> EncryptionEncodingT: ...
def xor(self: EncryptionEncodingT, key: str, key_type: Literal['hex', 'utf', 'base64']=..., ascii: bool=...) -> EncryptionEncodingT: ...
def xor_bruteforce(self: EncryptionEncodingT, length: int=...) -> EncryptionEncodingT: ...
def jwt_decode(self: EncryptionEncodingT) -> EncryptionEncodingT: ...
Expand Down
6 changes: 6 additions & 0 deletions tests/test_encryptionencoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ def test_rot_47():
assert Chepy("some").rot_47().out == "D@>6"


def test_rot_47_bruteforce():
c = Chepy("96==@").rot_47_bruteforce().o
assert c["1"] == ":7>>A"
assert c["47"] == "hello"


def test_rotate():
assert Chepy("some data").rotate(20).out == "migy xunu"

Expand Down

0 comments on commit 0040741

Please sign in to comment.