Skip to content

Commit

Permalink
πŸ—“ May 14, 2023 12:29:43 PM
Browse files Browse the repository at this point in the history
πŸ› fix key_format to key_mode in types
✨ monoalphabetic_substitution method
  • Loading branch information
securisec committed May 14, 2023
1 parent 89713c4 commit 8794970
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Misc:
☐ cyberchef recipe to chepy recipe converter

Archive:
βœ” ✨ monoalphabetic substitution
βœ” ✨ from nato
βœ” for join_by handle int
βœ” ip from int and vice versa @project(New ideas)
Expand Down
2 changes: 1 addition & 1 deletion chepy/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "5.0.1" # pragma: no cover
__version__ = "5.1.0" # pragma: no cover
__author__ = "Hapsida @securisec" # pragma: no cover
25 changes: 22 additions & 3 deletions chepy/modules/encryptionencoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import codecs
import itertools
import string
from typing import Literal, TypeVar
from typing import Literal, TypeVar, Dict

import lazy_import

Expand Down Expand Up @@ -603,7 +603,7 @@ def aes_encrypt(
key_format: str = "hex",
iv_format: str = "hex",
) -> EncryptionEncodingT:
"""Encrypt raw state with AES.
"""Encrypt raw state with AES.
CFB mode reflects Cyberchef and not native python behaviour.
Args:
Expand Down Expand Up @@ -664,7 +664,7 @@ def aes_decrypt(
key_format: str = "hex",
iv_format: str = "hex",
) -> EncryptionEncodingT:
"""Decrypt raw state encrypted with DES.
"""Decrypt raw state encrypted with DES.
CFB mode reflects Cyberchef and not native python behaviour.
Args:
Expand Down Expand Up @@ -1052,3 +1052,22 @@ def rsa_verify(
h = Hash.SHA256.new(self._convert_to_bytes())
self.state = PKCS1_15.new(key).verify(h, signature)
return self

@ChepyDecorators.call_stack
def monoalphabetic_substitution(
self, mapping: Dict[str, str] = {}
) -> EncryptionEncodingT:
"""Monoalphabetic substitution. Re-map characters
Args:
mapping (Dict[str, str], optional): Mapping of characters where key is the character to map and value is the new character to replace with. Defaults to {}.
Returns:
Chepy: The Chepy object
"""
hold = ""
cipher = self._convert_to_str()
for c in cipher:
hold += mapping.get(c.lower(), c)
self.state = hold
return self
19 changes: 10 additions & 9 deletions chepy/modules/encryptionencoding.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ..core import ChepyCore
from typing import Any, TypeVar, Literal
from typing import Any, TypeVar, Literal, Dict

jwt: Any
AES: Any
Expand All @@ -26,14 +26,14 @@ class EncryptionEncoding(ChepyCore):
def jwt_bruteforce(self: EncryptionEncodingT, wordlist: str, b64_encode: bool=..., algorithm: list=...) -> EncryptionEncodingT: ...
def rc4_encrypt(self: EncryptionEncodingT, key: str, key_format: RC4_FORMAT=...) -> EncryptionEncodingT: ...
def rc4_decrypt(self: EncryptionEncodingT, key: str, key_format: RC4_FORMAT=...) -> EncryptionEncodingT: ...
def des_encrypt(self: EncryptionEncodingT, key: str, iv: str=..., mode: Literal["CBC", "OFB", "CTR", "ECB"]=..., key_mode: FORMAT=..., iv_format: FORMAT=...) -> EncryptionEncodingT: ...
def des_decrypt(self: EncryptionEncodingT, key: str, iv: str=..., mode: Literal["CBC", "OFB", "CTR", "ECB"]=..., key_mode: FORMAT=..., iv_format: FORMAT=...) -> EncryptionEncodingT: ...
def triple_des_encrypt(self: EncryptionEncodingT, key: str, iv: str=..., mode: Literal["CBC", "OFB", "CTR", "ECB"]=..., key_mode: FORMAT=..., iv_format: FORMAT=...) -> EncryptionEncodingT: ...
def triple_des_decrypt(self: EncryptionEncodingT, key: str, iv: str=..., mode: Literal["CBC", "OFB", "CTR", "ECB"]=..., key_mode: FORMAT=..., iv_format: FORMAT=...) -> EncryptionEncodingT: ...
def aes_encrypt(self: EncryptionEncodingT, key: str, iv: str=..., mode: Literal["CBC", "CFB", "OFB", "CTR", "ECB", "GCM"]=..., key_mode: FORMAT=..., iv_format: FORMAT=...) -> EncryptionEncodingT: ...
def aes_decrypt(self: EncryptionEncodingT, key: str, iv: str=..., mode: Literal["CBC", "CFB", "OFB", "CTR", "ECB", "GCM"]=..., key_mode: FORMAT=..., iv_format: FORMAT=...) -> EncryptionEncodingT: ...
def blowfish_encrypt(self: EncryptionEncodingT, key: str, iv: str=..., mode: Literal["CBC", "OFB", "CTR", "ECB"]=..., key_mode: FORMAT=..., iv_format: FORMAT=...) -> EncryptionEncodingT: ...
def blowfish_decrypt(self: EncryptionEncodingT, key: str, iv: str=..., mode: Literal["CBC", "OFB", "CTR", "ECB"]=..., key_mode: FORMAT=..., iv_format: FORMAT=...) -> EncryptionEncodingT: ...
def des_encrypt(self: EncryptionEncodingT, key: str, iv: str=..., mode: Literal["CBC", "OFB", "CTR", "ECB"]=..., key_format: FORMAT=..., iv_format: FORMAT=...) -> EncryptionEncodingT: ...
def des_decrypt(self: EncryptionEncodingT, key: str, iv: str=..., mode: Literal["CBC", "OFB", "CTR", "ECB"]=..., key_format: FORMAT=..., iv_format: FORMAT=...) -> EncryptionEncodingT: ...
def triple_des_encrypt(self: EncryptionEncodingT, key: str, iv: str=..., mode: Literal["CBC", "OFB", "CTR", "ECB"]=..., key_format: FORMAT=..., iv_format: FORMAT=...) -> EncryptionEncodingT: ...
def triple_des_decrypt(self: EncryptionEncodingT, key: str, iv: str=..., mode: Literal["CBC", "OFB", "CTR", "ECB"]=..., key_format: FORMAT=..., iv_format: FORMAT=...) -> EncryptionEncodingT: ...
def aes_encrypt(self: EncryptionEncodingT, key: str, iv: str=..., mode: Literal["CBC", "CFB", "OFB", "CTR", "ECB", "GCM"]=..., key_format: FORMAT=..., iv_format: FORMAT=...) -> EncryptionEncodingT: ...
def aes_decrypt(self: EncryptionEncodingT, key: str, iv: str=..., mode: Literal["CBC", "CFB", "OFB", "CTR", "ECB", "GCM"]=..., key_format: FORMAT=..., iv_format: FORMAT=...) -> EncryptionEncodingT: ...
def blowfish_encrypt(self: EncryptionEncodingT, key: str, iv: str=..., mode: Literal["CBC", "OFB", "CTR", "ECB"]=..., key_format: FORMAT=..., iv_format: FORMAT=...) -> EncryptionEncodingT: ...
def blowfish_decrypt(self: EncryptionEncodingT, key: str, iv: str=..., mode: Literal["CBC", "OFB", "CTR", "ECB"]=..., key_format: FORMAT=..., iv_format: FORMAT=...) -> EncryptionEncodingT: ...
def vigenere_encode(self: EncryptionEncodingT, key: str) -> EncryptionEncodingT: ...
def vigenere_decode(self: EncryptionEncodingT, key: str) -> EncryptionEncodingT: ...
def affine_encode(self: EncryptionEncodingT, a: int=..., b: int=...) -> EncryptionEncodingT: ...
Expand All @@ -46,3 +46,4 @@ class EncryptionEncoding(ChepyCore):
def rsa_decrypt(self: EncryptionEncodingT, priv_key_path: str) -> EncryptionEncodingT: ...
def rsa_sign(self: EncryptionEncodingT, priv_key_path: str) -> EncryptionEncodingT: ...
def rsa_verify(self: EncryptionEncodingT, signature: bytes, public_key_path: str) -> EncryptionEncodingT: ...
def monoalphabetic_substitution(self: EncryptionEncodingT, mapping: Dict[str, str]=...): ...
4 changes: 4 additions & 0 deletions tests/test_encryptionencoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,3 +556,7 @@ def test_rsa_sign():
Chepy("lol").rsa_sign("tests/files/private.pem").to_hex().o
== b"ae12fa91f12af7e1c04e7893ce43fc76195d30203ad0ab88fac3631feb026ee8832d57584a977fe9f70139d8dd7c74b904643ab11493935c642e563752325c1ecde98a29bfaaa714e513d7c3548e9fbea6f2f2705eec3567f4ba868b3ca16f8ede4155e71b854042810bb836dda031c2e540175f4573103c065311d38b7246a6"
)


def test_monoalphabetic_substitution():
assert Chepy("lol").monoalphabetic_substitution({"l": "t", "o": "s"}).o == "tst"

0 comments on commit 8794970

Please sign in to comment.