Chepy Class¶
The Chepy class in the main class for Chepy, and includes all the methods from all the different classes under modules. This class takes *args as its argument, and each argument that is passed to it becomes its own state.
>>> from chepy import Chepy
>>> c = Chepy("some data", "/some/path/file")
>>> c.states
{0: "some data", 1: "/some/path/file"}
- class chepy.Chepy(*data)¶
Chepy class that exposes all functionality of Chepy and its plugins.
- add(n: int) AritmeticLogicT ¶
Add a number to the state
- Parameters
n (int) – Number to add with. Can be decimal or hex string without 0x
- Returns
The Chepy object.
- Return type
- addition(delimiter=None) AritmeticLogicT ¶
Adds a list of numbers. If an item in the string is not a number it is excluded from the list.
- Parameters
delimiter (str, optional) – Delimiter. Defaults to None.
- Returns
The Chepy object.
- Return type
- aes_decrypt(key: str, iv: str = '00000000000000000000000000000000', mode: str = 'CBC', key_format: str = 'hex', iv_format: str = 'hex') EncryptionEncodingT ¶
Decrypt raw state encrypted with AES. CFB mode reflects Cyberchef and not native python behaviour.
- Parameters
key (str) – Required. The secret key
iv (str, optional) – IV for certain modes only. Defaults to ‘00000000000000000000000000000000’.
mode (str, optional) – Encryption mode. Defaults to ‘CBC’.
key_format (str, optional) – Format of key. Defaults to ‘hex’.
iv_format (str, optional) – Format of IV. Defaults to ‘hex’.
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("5fb8c186394fc399849b89d3b6605fa3") >>> c.hex_to_str() >>> c.aes_decrypt("7365637265742070617373776f726421") >>> c.o b"some data"
- aes_encrypt(key: str, iv: str = '00000000000000000000000000000000', mode: str = 'CBC', key_format: str = 'hex', iv_format: str = 'hex') EncryptionEncodingT ¶
Encrypt raw state with AES. CFB mode reflects Cyberchef and not native python behaviour.
- Parameters
key (str) – Required. The secret key
iv (str, optional) – IV for certain modes only. Defaults to ‘00000000000000000000000000000000’.
mode (str, optional) – Encryption mode. Defaults to ‘CBC’.
key_format (str, optional) – Format of key. Defaults to ‘hex’.
iv_format (str, optional) – Format of IV. Defaults to ‘hex’.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("some data").aes_encrypt("secret password!", mode="ECB").o b"5fb8c186394fc399849b89d3b6605fa3"
- affine_decode(a: int = 1, b: int = 1) EncryptionEncodingT ¶
Decode Affine cipher
- Parameters
a (int, optional) – Multiplier value. Defaults to 1
b (int, optional) – Additive value. Defaults to 1
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("TFDSFU").affine_decode().o "SECRET"
- affine_encode(a: int = 1, b: int = 1) EncryptionEncodingT ¶
Encode with Affine cipher
- Parameters
a (int, optional) – Multiplier value. Defaults to 1
b (int, optional) – Additive value. Defaults to 1
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("secret").affine_encode().o "TFDSFU"
- atbash_decode() EncryptionEncodingT ¶
Decode Atbash cipher
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("hvxivg").atbash_decode().o "SECRET"
- atbash_encode() EncryptionEncodingT ¶
Encode with Atbash cipher
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("secret").atbash_encode().o "HVXIVG"
- aws_account_id_from_access_key()¶
Extract AWS account id from access key
- Returns
The Chepy object.
- Return type
- bcrypt_compare(hash: str) HashingT ¶
Compare Bcrypt hash
Tests whether the provided hash matches the given string at init.
- Parameters
hash (str) – Required. brypt hash
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("abc") >>> c.bcrypt_compare("$2a$10$SpXMRnrQ4IQqC710xMHfAu0BBr4nJkuPqDvzhiAACnykgn87iE2S2") True
- bcrypt_hash(rounds: int = 10) HashingT ¶
Get Bcrypt hash
- Parameters
rounds (int, optional) – rounds of hashing, by default 10
- Returns
The Chepy object.
- Return type
- beautify_json(indent: int = 2) CodeTidyT ¶
Beautify minified JSON
- Parameters
indent (int, optional) – Indent level. Defaults to 2.
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("/path/to/file.json").load_file() >>> print(c.beautify_json(indent=4))
- bifid_decode(key: Union[str, bytes] = '')¶
Bifid / polybius decode
- Parameters
key (Union[str, bytes], optional) – Key. Defaults to “”.
- Returns
The Chepy object.
- Return type
- bifid_encode(key: Union[bytes, str] = '') EncryptionEncodingT ¶
Bifid / polybius decode
- Parameters
key (Union[str, bytes], optional) – Key. Defaults to “”.
- Returns
The Chepy object.
- Return type
- binary_to_hex() DataFormatT ¶
Converts binary data into a hex string
- Returns
The Chepy object.
- Return type
- bit_shift_left(amount: int = 1)¶
Shifts each byte in the input byte array to the left by a specified amount.
- Parameters
amount (int, optional) – Amount. Defaults to 1.
- Returns
The Chepy object.
- Return type
- bit_shift_right(amount: int = 1, operation_type: Literal['logical', 'arithmetic'] = 'logical') AritmeticLogicT ¶
Shifts the bits in each byte towards the right by the specified amount.
- Parameters
amount (int, optional) – Amount. Defaults to 1
operation_type (Literal['logical', 'arithmetic'], optional) – Operation type. Defaults to ‘logical’.
- Returns
The Chepy object.
- Return type
- blake_2b(bits: int = 256, key: bytes = '') HashingT ¶
Get Balke-2b hash
- Parameters
bits (int, optional) – Number of digest bits, by default 256
key (bytes, optional) – Encryption secret key, by default ‘’
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("A").blake_2b(bits=128, key="key").out "6d2e4cba3bc564e02d1a76f585a6795d"
- blake_2s(bits: int = 256, key: bytes = '') HashingT ¶
Get Blake-2s hash
- Parameters
bits (int, optional) – Number of digest bits, by default 256
key (bytes, optional) – Encryption secret key, by default ‘’
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("A").blake_2s(bits=128, key="key").out "4e33cc702e9d08c28a5e9691f23bc66a"
- blowfish_decrypt(key: str, iv: str = '0000000000000000', mode: str = 'CBC', key_format: str = 'hex', iv_format: str = 'hex') EncryptionEncodingT ¶
Encrypt raw state with Blowfish
- Parameters
key (str) – Required. The secret key
iv (str, optional) – IV for certain modes only. Defaults to ‘00000000000000000000000000000000’.
mode (str, optional) – Encryption mode. Defaults to ‘CBC’.
key_format (str, optional) – Format of key. Defaults to ‘hex’.
iv_format (str, optional) – Format of IV. Defaults to ‘hex’.
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("d9b0a79853f13960fcee3cae16e27884") >>> c.hex_to_str() >>> c.blowfish_decrypt("password", key_format="utf-8") >>> c.o b"some data"
- blowfish_encrypt(key: str, iv: str = '0000000000000000', mode: str = 'CBC', key_format: str = 'hex', iv_format: str = 'hex') EncryptionEncodingT ¶
Encrypt raw state with Blowfish
- Parameters
key (str) – Required. The secret key
iv (str, optional) – IV for certain modes only. Defaults to ‘0000000000000000’.
mode (str, optional) – Encryption mode. Defaults to ‘CBC’.
key_format (str, optional) – Format of key. Defaults to ‘hex’.
iv_format (str, optional) – Format of IV. Defaults to ‘hex’.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("some data").blowfish_encrypt("password", mode="ECB").o b"d9b0a79853f139603951bff96c3d0dd5"
- bruteforce_from_base_xx() DataFormatT ¶
Bruteforce various base encodings. Current supports base85, base16, base32, base64, base85, base58
- Returns
The Chepy object.
- Return type
- bytearray_to_str(encoding: str = 'utf8', errors: str = 'replace') DataFormatT ¶
Convert a python bytearray to string
- Parameters
encoding (str, optional) – String encoding. Defaults to ‘utf8’.
errors (str, optional) – How errors should be handled. Defaults to replace.
- Raises
TypeError – If state is not a bytearray
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy(bytearray("lolol", "utf")).bytearray_to_str().o "lolol"
- bytes_to_ascii() DataFormatT ¶
Convert bytes (array of bytes) to ascii
- Returns
The Chepy object.
- Return type
- bzip_compress() CompressionT ¶
Compress the state into bz2 archive
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("some data").bzip_compress() b'BZh91AY&SY\x9f\xe2\xaa\x9d\x00\x00\x03...
We can now write this as a bz2 file with >>> c.write(“/path/to/file.bz2”, as_binary=True)
- bzip_decompress() CompressionT ¶
Decompress a bz2 archive
- Returns
The Chepy object.
- Return type
- callback(callback_function: Callable[[Any], Any])¶
Run any user defined python function against the state. This method is not recorded in the recipes
- Parameters
callback_function (Callable[[Any], Any]) – The function to run. The function should take one argument (the state is passed to it). It can return Any
Examples
from chepy import Chepy
- def cb(data):
return data * 2
c = Chepy(‘abc’).callback(cb) # state is now abcabc
- Returns
The Chepy object.
- Return type
- chacha_decrypt(key: str, nonce: str = '0000000000000000', key_format: str = 'hex', nonce_format: str = 'hex') EncryptionEncodingT ¶
Decrypt raw state encrypted with ChaCha 20 rounds.
- Parameters
key (str) – Required. The secret key
nonce (str, optional) – nonce for certain modes only. Defaults to ‘0000000000000000’.
key_format (str, optional) – Format of key. Defaults to ‘hex’.
nonce_format (str, optional) – Format of nonce. Defaults to ‘hex’.
- Returns
The Chepy object.
- Return type
- chacha_encrypt(key: str, nonce: str = '0000000000000000', key_format: str = 'hex', nonce_format: str = 'hex') EncryptionEncodingT ¶
Encrypt raw state with ChaCha 20 rounds
- Parameters
key (str) – Required. The secret key
nonce (str, optional) – Nonce. Defaults to ‘0000000000000000’.
key_format (str, optional) – Format of key. Defaults to ‘hex’.
nonce_format (str, optional) – Format of nonce. Defaults to ‘hex’.
- Returns
The Chepy object.
- Return type
- change_state(index: int)¶
Change current state by index
Same behaviour as switch_state
- Parameters
index (int) – Index of new state
- Raises
TypeError – If specified index does not exist
- Returns
The Chepy object.
- Return type
- concat(data: Union[str, bytes]) DataFormatT ¶
Concat bytes to the current state
- Parameters
data (Union[str, bytes]) – Data to add
- Returns
The Chepy object. s
- Return type
- copy() None ¶
Copy to clipboard
Copy the final output to the clipboard. If an error is raised, refer to the documentation on the error.
- Returns
Copies final output to the clipboard
- Return type
None
- copy_state(index: int = None)¶
Copy the current state to a new state
- Parameters
index (int) – Index of new state. Defaults to next available.
- Returns
The Chepy object.
- Return type
- copy_to_clipboard() None ¶
Copy to clipboard
Copy the final output to the clipboard. If an error is raised, refer to the documentation on the error.
- Returns
Copies final output to the clipboard
- Return type
None
- count_occurances(regex: str, case_sensitive: bool = False) UtilsT ¶
Counts occurrences of the regex.
Counts the number of times the provided string occurs.
- Parameters
regex (str) – Required. Regex string to search for
case_sensitive (bool, optional) – If search should be case insensitive, by default False
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("AABCDADJAKDJHKSDAJSDdaskjdhaskdjhasdkja").count_occurances("ja").out 2
- crc32_checksum() HashingT ¶
Get CRC32 checksum
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("a").crc32_checksum().out "e8b7be43"
- create_zip_file(file_name: str) CompressionT ¶
Create a zip archive with data from state
- Parameters
file_name (str) – File name for file inside zip archive
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("some data").create_zip_file() >>> c.write("/some/path/file.zip", as_binary=True)
- css_selector(query: str)¶
Extract data using valid CSS selectors
- Parameters
query (str) – Required. CSS query
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("http://example.com") >>> c.http_request() >>> c.css_selector("title") >>> c.get_by_index(0) >>> c.o "<title>Example Domain</title>"
- cut(start: int, end: int) DataFormatT ¶
Convert the state to bytes and cut x:y data from it
- Parameters
start (int) – Starting position
end (int) – End position
- Returns
The Chepy object.
- Return type
- debug(verbose: bool = False)¶
Debug the current instance of Chepy
This method does not change the state.
- Parameters
verbose (bool, optional) – Show verbose info. Defaults to False.
- Returns
The Chepy object.
- Return type
- decode(encoding: str, errors: str = 'backslashreplace') LanguageT ¶
Decode the string using the given encoding.
- Parameters
encoding (str) – Encoding to use.
errors (str, optional) – How to handle errors when decoding. Defaults to ‘backslashreplace’.
- Returns
The Chepy object.
- Return type
- decode_bruteforce() DataFormatT ¶
Bruteforce the various decoding for a string
Enumerates all supported text encodings for the input, allowing you to quickly spot the correct one. Reference
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("m\xfcnchen\ud55c").decode_bruteforce() { ... 'unicode_escape': 'münchen한', 'utf_16': '屭晸湣档湥畜㕤挵', 'utf_16_be': '浜硦据捨敮屵搵㕣', ... }
- decode_bytes(errors: str = 'ignore') DataFormatT ¶
Decode bytes to string
- Parameters
errors (str, optional) – Ignore or replace error chars. Defaults to ‘ignore’.
- Returns
The Chepy object.
- Return type
- decode_zero_width(_zw_chars: str = '\u200c\u200d\u202c\ufeff') ExtractorsT ¶
Extract zero with characters. Decode implementation of https://330k.github.io/misc_tools/unicode_steganography.html
- Parameters
chars (str, optional) – Characters for stego. Defaults to ‘’.
- Returns
The Chepy object.
- Return type
- decrement_bytes(n: int) DataFormatT ¶
Loop through each byte and decrement
- Parameters
n (int) – decrement by.
- Returns
The Chepy object.
- Return type
- defang_ip() NetworkingT ¶
Make an IP address harmless
Takes a IPv4 or IPv6 address and ‘Defangs’ it, meaning the IP becomes invalid, removing the risk of accidentally utilising it as an IP address.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("2001:4860:4860::8844").defang_ip().o "2001[:]4860[:]4860[:][:]8844"
>>> Chepy("127.0.0.1").defang_ip().o "127[.]0[.]0[.]1"
- defang_url() NetworkingT ¶
Make a URL harmless
Takes a Universal Resource Locator (URL) and ‘Defangs’ it; meaning the URL becomes invalid, neutralising the risk of accidentally clicking on a malicious link. This is often used when dealing with malicious links or IOCs.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("https://app.google.com/?lol=some data&a=1").defang_url().o "hxxps://app[.]google[.]com/?lol=some data&a=1"
- delete_buffer(index: int)¶
Delete a buffer item
- Parameters
index (int) – Key of buffer item
- Returns
The Chepy object.
- Return type
- delete_state(index: int)¶
Delete a state specified by the index
- Parameters
index (int) – Index of state
- Returns
The Chepy object.
- Return type
- der_hex_to_pem() PublickeyT ¶
Convert DER format to PEM cert.
Converts a hexadecimal DER (Distinguished Encoding Rules) string into PEM (Privacy Enhanced Mail) format.
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy(str(Path().absolute() / "tests/files/test.der")) >>> c.load_file() >>> c.der_hex_to_pem() >>> c.o.decode() -----BEGIN CERTIFICATE----- MIICeTCCAeICCQDi5dgCpKMeHTANBgkqhkiG9w0BAQsFADCBgDELMAkGA1UEBhMC VVMxDDAKBgNVBAgMA2xvbDEMMAoGA1UEBwwDbnljMRIwEAYDVQQKDAlzZWN1cmlz ... wQSFm54UNQ/vjM12yZ+C5c3268Vo8jSP7mI5R3wn6XztjUSXkDg5/3IL3kojti/h nyhBHx2QCVke7BxWw3HWkbZ/1BKl0HnCGyd5HDTuOtlBmTS+QrJoNpdsn0zq4fvc igbV1IJdKTBAiZzaOQ== -----END CERTIFICATE-----
- derive_pbkdf2_key(password: Union[str, bytes], salt: Union[str, bytes], key_size: int = 256, iterations: int = 1000, hash_type: Literal['md5', 'sha1', 'sha256', 'sha512'] = 'sha1', hex_salt: bool = True, show_full_key: bool = False)¶
Derive a PBKDF2 key
- Parameters
password (Union[str, bytes]) – Password
salt (Union[str, bytes]) – Salt
key_size (int, optional) – Key size. Defaults to 256.
iterations (int, optional) – Number of iterations. Defaults to 1000.
hash_type (Literal[, optional) – Hash type. Defaults to “sha1”.
hex_salt (bool, optional) – If salt is in hex format. Defaults to True.
show_full_key (bool, optional) – Show AES256 64 bit key only. Defaults to False.
- Raises
TypeError – If hash type is not one of md5, sha1, sha256, sha512
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy(".").derive_pbkdf2_key("mR3m", "d9016d44c374f5fb62604683f4d61578").o[:10] "7c8898f222"
- des_decrypt(key: str, iv: str = '0000000000000000', mode: str = 'CBC', key_format: str = 'hex', iv_format: str = 'hex') EncryptionEncodingT ¶
Decrypt raw state encrypted with DES.
- Parameters
key (str) – Required. The secret key
iv (str, optional) – IV for certain modes only. Defaults to ‘0000000000000000’.
mode (str, optional) – Encryption mode. Defaults to ‘CBC’.
key_format (str, optional) – Format of key. Defaults to ‘hex’.
iv_format (str, optional) – Format of IV. Defaults to ‘hex’.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("1ee5cb52954b211d1acd6e79c598baac").hex_to_str().des_decrypt("password").o b"some data"
- des_encrypt(key: str, iv: str = '0000000000000000', mode: str = 'CBC', key_format: str = 'hex', iv_format: str = 'hex') EncryptionEncodingT ¶
Encrypt raw state with DES
- Parameters
key (str) – Required. The secret key
iv (str, optional) – IV for certain modes only. Defaults to ‘0000000000000000’.
mode (str, optional) – Encryption mode. Defaults to ‘CBC’.
key_format (str, optional) – Format of key. Defaults to ‘hex’.
iv_format (str, optional) – Format of IV. Defaults to ‘hex’.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("some data").des_encrypt("70617373776f7264").o b"1ee5cb52954b211d1acd6e79c598baac"
To encrypt using a different mode
>>> Chepy("some data").des_encrypt("password", mode="CTR").o b"0b7399049b0267d93d"
- dict_get_items(*keys: str) DataFormatT ¶
Get items from a dict. If no keys are specified, it will return all items. :returns: The Chepy object. :rtype: Chepy
Examples
>>> o = Chepy({"a": 1, "b": 2}).dict_get_items("a", "b", "c").o [1, 2]
- dict_to_json() DataFormatT ¶
Convert a dict object to a JSON string
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy({"some": "data", "a": ["list", 1, True]}).dict_to_json().o '{"some":"data","a":["list",1,true]}'
- diff(state: int = None, buffer: int = None, colors: bool = False, swap: bool = False, only_changes: bool = False)¶
Diff state with another state or buffer
- Parameters
state (int, optional) – Index of state to compare against. Defaults to None.
buffer (int, optional) – Index of buffer to compare against. Defaults to None.
colors (bool, optional) – Show colored diff. Defaults to False.
swap (bool, optional) – Swap the diff order. Defaults to False.
only_changes (bool, optional) – Return only changes. Defaults to False.
- Raises
TypeError – If both state and buffer is set to True.
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("first string", "First $trin") >>> # there are two states >>> c.diff(state=1) # this will diff state 0 with state 1 {F->f}irst {-$}strin{+g} >>> # optionally set colors=True in the diff method to see colored output
- divide(n: int) AritmeticLogicT ¶
Divide a number to the state. Chepy is not optimized for float math. Subsequent methods may fail.
- Parameters
n (int) – Number to divide with
- Returns
The Chepy object.
- Return type
- drop_bytes(start: int, length: int) UtilsT ¶
Drop bytes from starting index up to length
- Parameters
start (int) – Starting index
length (int) – Number of bytes to drop
- Raises
ValueError – If start or length < -1
- Returns
The Chepy object
- Return type
- dump_pkcs12_cert(password: str) PublickeyT ¶
Get the private key and cert from pkcs12 cert
- Parameters
password (str) – Password for certificate
- Returns
The Chepy object.
- Return type
- encode(encoding: str, errors: str = 'backslashreplace') LanguageT ¶
Encode the string using the given encoding.
- Parameters
encoding (str) – Encoding to use.
errors (str, optional) – How to handle errors when encoding. Defaults to ‘backslashreplace’.
- Returns
The Chepy object.
- Return type
- encode_bruteforce() DataFormatT ¶
Bruteforce the various encoding for a string
Enumerates all supported text encodings for the input, allowing you to quickly spot the correct one. Reference
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("münchen한").encode_bruteforce() { 'ascii': b'm\xfcnchen\ud55c', 'base64_codec': b'bcO8bmNoZW7tlZw=\n', 'big5': b'm\xfcnchen\ud55c', 'big5hkscs': b'm\x88\xa2nchen\ud55c', ... }
- encode_us_ascii_7_bit() LanguageT ¶
Encode state using US ascii 7 bit
- Returns
The Chepy object.
- Return type
- escape_string() UtilsT ¶
Escape all special characters in a string
- Returns
The Chepy object.
- Return type
- eval_state() DataFormatT ¶
Eval state as python. Handy when converting string representation of objects.
- Returns
The Chepy object
- Return type
- expand_alpha_range(join_by: Optional[str] = None)¶
Get all alphanumberic or hex chars for the specified range
- Parameters
join_by (str, optional) – Join by. Defaults to Union[str, None].
- Returns
The Chepy object.
- Return type
- extract_auth_basic() ExtractorsT ¶
Extract basic authentication tokens
- Returns
The Chepy object.
- Return type
- extract_auth_bearer() ExtractorsT ¶
Extract bearer authentication tokens
- Returns
The Chepy object.
- Return type
- extract_base64(min: int = 20) ExtractorsT ¶
Extract base64 encoded strings
- Parameters
min (int, optional) – Minimum length to match. Defaults to 20.
- Returns
The Chepy object.
- Return type
- extract_domains(is_binary: bool = False) ExtractorsT ¶
Extract domains
- Parameters
is_binary (bool, optional) – The state is in binary format. It will then first extract the strings from it before matching.
- Returns
The Chepy object.
- Return type
- extract_dsa_private() ExtractorsT ¶
Extract DSA private key
- Returns
The Chepy object.
- Return type
- extract_email(is_binary: bool = False) ExtractorsT ¶
Extract email
- Parameters
is_binary (bool, optional) – The state is in binary format. It will then first extract the strings from it before matching.
- Returns
The Chepy object.
- Return type
Examples
Sometimes, the state is in a binary format, and not readable. In this case set the binary flag to True.
>>> Chepy("tests/files/test.der").load_file().extract_email(is_binary=True).o
- extract_facebook_access_token() ExtractorsT ¶
Extract Facebook access tokens
- Returns
The Chepy object.
- Return type
- extract_github() ExtractorsT ¶
Extract Github access token
- Returns
The Chepy object.
- Return type
- extract_google_api() ExtractorsT ¶
Extract Goolge api keys
- Returns
The Chepy object.
- Return type
- extract_google_captcha() ExtractorsT ¶
Extract Goolge captcha keys
- Returns
The Chepy object.
- Return type
- extract_google_oauth() ExtractorsT ¶
Extract Goolge oauth keys
- Returns
The Chepy object.
- Return type
- extract_hashes() ExtractorsT ¶
Extract md5, sha1, sha256 and sha512 hashes
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy( >>> ["60b725f10c9c85c70d97880dfe8191b3", "3f786850e387550fdab836ed7e6dc881de23001b"] >>> ).extract_hashes() {'md5': [b'60b725f10c9c85c70d97880dfe8191b3'], 'sha1': [b'3f786850e387550fdab836ed7e6dc881de23001b'], 'sha256': [], 'sha512': []}
- extract_html_tags(tags: List[str])¶
Extract tags from html along with their attributes
- Parameters
tag (str) – A HTML tag
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("http://example.com").http_request().html_tags(['p']).o [ {'tag': 'p', 'attributes': {}}, {'tag': 'p', 'attributes': {}}, {'tag': 'p', 'attributes': {}} ]
- extract_ips(is_binary: bool = False) ExtractorsT ¶
Extract ipv4 and ipv6 addresses
- Parameters
is_binary (bool, optional) – The state is in binary format. It will then first extract the strings from it before matching.
- Returns
The Chepy object.
- Return type
- extract_mac_address(is_binary: bool = False) ExtractorsT ¶
Extract MAC addresses
- Parameters
is_binary (bool, optional) – The state is in binary format. It will then first extract the strings from it before matching.
- Returns
The Chepy object.
- Return type
- extract_mailgun_api() ExtractorsT ¶
Extract Mailgun API key
- Returns
The Chepy object.
- Return type
- extract_paypal_bt() ExtractorsT ¶
Extract Paypal braintree access token
- Returns
The Chepy object.
- Return type
- extract_rsa_private() ExtractorsT ¶
Extract RSA private key
- Returns
The Chepy object.
- Return type
- extract_square_access() ExtractorsT ¶
Extract Square access token
- Returns
The Chepy object.
- Return type
- extract_square_oauth() ExtractorsT ¶
Extract Square oauth secret token
- Returns
The Chepy object.
- Return type
- extract_strings(length: int = 4, join_by: Union[str, bytes] = '\n') ExtractorsT ¶
Extract strings from state
- Parameters
length (int, optional) – Min length of string. Defaults to 4.
join_by (str, optional) – String to join by. Defaults to newline.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("tests/files/hello").load_file().extract_strings().o __PAGEZERO' __TEXT' __text' __TEXT' __stubs' __TEXT' ...
- extract_stripe_api() ExtractorsT ¶
Extract Stripe standard or restricted api token
- Returns
The Chepy object.
- Return type
- extract_twilio_api() ExtractorsT ¶
Extract Twilio API key
- Returns
The Chepy object.
- Return type
- extract_twilio_sid() ExtractorsT ¶
Extract Twilio account or app sid
- Returns
The Chepy object.
- Return type
- extract_urls(is_binary: bool = False) ExtractorsT ¶
Extract urls including http, file, ssh and ftp
- Parameters
is_binary (bool, optional) – The state is in binary format. It will then first extract the strings from it before matching.
- Returns
The Chepy object.
- Return type
- extract_zero_width_chars_tags() ExtractorsT ¶
Extract zero width characters between U+E0000 to U+E007F. Implements https://www.irongeek.com/i.php?page=security/unicode-steganography-homoglyph-encoder
- Returns
The Chepy object.
- Return type
- fernet_decrypt(key: Union[bytes, str], encode_key: bool = False) EncryptionEncodingT ¶
Fernet decrypt
- Parameters
key (Union[bytes, str]) – Key to encrypt with. This should be 32 bytes long
encode_key (bool, optional) – If key should be base64 encoded. Defaults to False.
- Returns
The Chepy object.
- Return type
- fernet_encrypt(key: Union[bytes, str], encode_key: bool = False) EncryptionEncodingT ¶
Fernet encrypt
- Parameters
key (Union[bytes, str]) – Key to encrypt with. This should be 32 bytes long
encode_key (bool, optional) – If key should be base64 encoded. Defaults to False.
- Returns
The Chepy object.
- Return type
- filter_dict_key(by: str) UtilsT ¶
Filter dictionary by key
- Parameters
by (str) – Required. Key to filter by.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy({'some': 'dict', 'another': 'val'}).filter_dict_key('ano') {'another': 'val'}
- filter_dict_value(by: str) UtilsT ¶
Filter dictionary by value.
This method does descend into nested dictionary values.
- Parameters
by (str) – Required. Value to filter by.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy({'some': 'dict', 'another': 'val'}).filter_dict_value('val') {'another': 'val'}
- filter_list(by: Union[str, dict], regex: bool = True) UtilsT ¶
Filter a list by a string regex or dict key
- Parameters
by (Union[str, dict]) – If string, supports regex. Or dictionary
regex (bool, optional) – If pattern is a regex. Defaults to True
- Raises
StateNotList – If state is not a list
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy('[{"a": 1}, {"b": 2}, {"a": 1, "b": 3}]').str_list_to_list().filter_list("b").o [{"b": 2}, {"a": 1, "b": 3}]
- filter_list_by_length(length: int, exact: bool = False) UtilsT ¶
Filter a list by length by specifying minimum length.
It will also return items that exceed the specified length.
- Parameters
length (int) – Minimum length to match
exact (bool) – Match exact length
- Returns
The Chepy object.
- Return type
- find_continuous_patterns(str2: Union[str, bytes], min_value: int = 10) ExtractorsT ¶
Find continius patterns between the state as a string and the provided str2
- Parameters
str2 (Union[str, bytes]) – String to find matches against
min_value (int, optional) – Minimum value of continuous matches. Defaults to 10.
- Returns
The Chepy object.
- Return type
- find_emojis() LanguageT ¶
Find emojis, symbols, pictographs, map symbols and flags
- Returns
The Chepy object.
- Return type
- find_longest_continious_pattern(str2: str) ExtractorsT ¶
Find longest continuous pattern
- Parameters
str2 (Union[str, bytes]) – String to find match against
- Returns
The Chepy object.
- Return type
- find_replace(pattern: str, repl: str, ignore_case=True) UtilsT ¶
Replace matched pattern with repln
- Parameters
pattern (str) – Required. Pattern to search
repl (str) – Required. Pattern to match
ignore_case (bool, optional) – Case insensitive. Defaults to True.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("some some data").find_replace("some\s", "data").o "datadatadata"
- fix_zip_header() CompressionT ¶
Fix the first 4 bytes of a zip file
- Returns
The Chepy object.
- Return type
- flatten() DataFormatT ¶
Flatten a list of lists into a single list
- Returns
The Chepy object.
- Return type
- for_each(methods: List[Tuple[Union[str, object], dict]], merge: Optional[Union[str, bytes]] = None)¶
Run multiple methods on current state if it is a list
Method names in a list of tuples. If using in the cli, this should not contain any spaces.
- Parameters
methods (List[Tuple[Union[str, object], dict]]) – Required. List of tuples
merge (Union[str, bytes, None]) – Merge data with. Defaults to None
- Returns
The Chepy object.
- Return type
Examples
This method takes an array of method names and their args as an list of tuples; the first value of the tuple is the method name as either a string, or as an object, and the second value is a ditionary of arguments. The keys of in the dictionary are method argument names, while the values are argument values.
>>> from chepy import Chepy >>> c = Chepy(['41', '42']) >>> c.for_each([("from_hex",), ("to_hex",)]) >>> # this is how to use fork methods with a string >>> c.for_each([(c.from_hex,), (c.to_hex,)]) >>> # This is how to use fork using methods >>> print(c) ['41', '42']
- fork(methods: List[Tuple[Union[str, object], dict]])¶
Run multiple methods on all available states
Method names in a list of tuples. If using in the cli, this should not contain any spaces.
- Parameters
methods (List[Tuple[Union[str, object], dict]]) – Required. List of tuples
- Returns
The Chepy object.
- Return type
Examples
This method takes an array of method names and their args as an list of tuples; the first value of the tuple is the method name as either a string, or as an object, and the second value is a ditionary of arguments. The keys of in the dictionary are method argument names, while the values are argument values.
>>> from chepy import Chepy >>> c = Chepy("some", "data") >>> c.fork([("to_hex",), ("hmac_hash", {"secret_key": "key"})]) >>> # this is how to use fork methods with a string >>> c.fork([(c.to_hex,), (c.hmac_hash, {"secret_key": "key"})]) >>> # This is how to use fork using methods >>> print(c.states) {0: 'e46dfcf050c0a0d135b73856ab8e3298f9cc4105', 1: '1863d1542629590e3838543cbe3bf6a4f7c706ff'}
- from_bacon(A: Literal['A', '0'] = 'A', B: Literal['B', '1'] = 'B', complete: bool = True, split_by: Union[str, bytes] = b' ', invert: bool = False) DataFormatT ¶
From Bacon
- Parameters
A (Literal['A','0'], optional) – A character. Defaults to ‘A’.
B (str, optional) – B character. Defaults to ‘B’.
complete (bool, optional) – Use unique mapping for all characters. Defaults to True.
split_by (Union[str,bytes], optional) – Split by. Defaults to b’ ‘.
invert (bool, optional) – Invert decoding. Defaults to False.
- Returns
The Chepy object.
- Return type
- from_base(radix: int = 36) DataFormatT ¶
Convert string to int base
- Parameters
radix (int, optional) – Radix. Defaults to 36.
- Returns
The Chepy object.
- Return type
- from_base32(remove_whitespace: bool = True) DataFormatT ¶
Decode as Base32
Base32 is a notation for encoding arbitrary byte data using a restricted set of symbols that can be conveniently used by humans and processed by computers. It uses a smaller set of characters than Base64, usually the uppercase alphabet and the numbers 2 to 7.
- Parameters
remove_whitespace (bool, optional) – If true, all whitespaces are removed
- Returns
The Chepy object.
- Return type
- from_base36(delimiter: Union[str, bytes] = ' ', join_by: Union[str, bytes] = ' ') DataFormatT ¶
Decode Base36 data
- Parameters
delimiter (Union[str, bytes], optional) – Delimiter to split groups of ints by. Defaults to ‘ ‘.
join_by (Union[str, bytes], optional) – Join final output by. Defaults to ‘ ‘.
- Returns
The Chepy object.
- Return type
- from_base58() DataFormatT ¶
Decode as Base58
Base58 is a notation for encoding arbitrary byte data using a restricted set of symbols that can be conveniently used by humans and processed by computers.This property decodes raw data into an ASCII Base58 string.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("2UDrs31qcWSPi").from_base58().out.decode() "some data"
- from_base62(alphabet: str = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz') DataFormatT ¶
Decode from base62
- Parameters
alphabet (str, optional) – Alphabet. Defaults to “0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz”.
- Returns
The Chepy object.
- Return type
- from_base64(alphabet: str = 'standard', remove_non_alpha: bool = True) DataFormatT ¶
Decode as Base64
Base64 is a notation for encoding arbitrary byte data using a restricted set of symbols that can be conveniently used by humans and processed by computers.This property decodes raw data into an ASCII Base64 string.
- Parameters
alphabet (str, optional) – Provide a custom charset to base64 with. Valid values are: filename_safe, itoa64, radix_64, rot13, standard, unix_crypt, url_safe, xml, xxencoding, z64
remove_whitespace (bool, optional) – If true, all whitespaces are removed (Defaults to True)
remove_non_alpha (bool, optional) – If true, all whitespaces are removed. (Defaults to True)
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("QqxhNG/mMKtYPqoz64FVR42=") >>> c.from_base64(alphabet="./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") >>> c.out b"some random? data"
- from_base85() DataFormatT ¶
Decode as Base85
Base85 is a notation for encoding arbitrary byte data using a restricted set of symbols that can be conveniently used by humans and processed by computers.This property decodes raw data into an ASCII Base58 string.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("F)Po,+Cno&@/").from_base85().out.decode() "some data"
- from_base91() DataFormatT ¶
Decode as Base91 Reference: https://github.com/aberaud/base91-python/blob/master/base91.py#L42
- Returns
The Chepy object.
- Return type
- from_binary(delimiter: str = None, byte_length: int = 8) DataFormatT ¶
Convert a list of binary numbers to string
- Parameters
delimiter (str, optional) – Delimiter. Defaults to ” “.
byte_length (int, optional) – Byte length. Defaults to 8.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("01100001 01100010 01100011").from_binary().o "abc"
- from_braille() DataFormatT ¶
Convert text to six-dot braille symbols
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("⠎⠑⠉⠗⠑⠞⠀⠍⠑⠎⠎⠁⠛⠑").from_braille().o "secret message"
- from_charcode(delimiter: str = None, join_by: str = '', base: int = 10) DataFormatT ¶
Convert array of unicode chars to string
- Parameters
delimiter (str, optional) – Delimiter. Defaults to ” “.
join_by (str, optional) – Join by. Defaults to “”.
base (int, optional) – Base. Defaults to 10.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("314e 61 20 41"]).from_charcode().o "ㅎa A"
- from_decimal(delimiter: str = None, join_by: str = '') DataFormatT ¶
Convert a list of decimal numbers to string
- Parameters
delimiter (str, optional) – Delimiter. Defaults to ” “.
join_by (str, optional) – Join by. Defaults to “”.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy(12622).from_decimal().o "ㅎ"
- from_hex(delimiter: str = None, join_by: str = '', replace: Optional[bytes] = b'%|0x') DataFormatT ¶
Convert a non delimited hex string to string
- Parameters
delimiter (str, optional) – Delimiter. Defaults to None.
join_by (str, optional) – Join by. Defaults to ‘ ‘.
replace (Union[bytes, None], optional) – Regex pattern to replace hex string prefixes. Defaults to b’%x|0x’.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("414141").from_hex().out b"AAA"
- from_hexdump() DataFormatT ¶
Convert hexdump back to str
- Returns
The Chepy object.
- Return type
- from_html_entity() DataFormatT ¶
Decode html entities
Decode special html characters like & > < etc
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("https://google.com&a="lol"").from_html_entity().o 'https://google.com&a="lol"'
- from_letter_number_code(delimiter: Union[str, bytes] = ' ', join_by: Union[str, bytes] = '') EncryptionEncodingT ¶
Decode A1Z26
- Parameters
delimiter (Union[str, bytes], optional) – Split on. Defaults to ‘ ‘.
join_by (Union[str, bytes], optional) – Join output by. Defaults to ‘’.
- Returns
The Chepy object.
- Return type
- from_morse_code(dot: str = '.', dash: str = '-', letter_delim: str = ' ', word_delim: str = '\n') EncryptionEncodingT ¶
Decode morse code
- Parameters
dot (str, optional) – The char for dot. Defaults to “.”.
dash (str, optional) – The char for dash. Defaults to “-“.
letter_delim (str, optional) – Letter delimiter. Defaults to ” “.
word_delim (str, optional) – Word delimiter. Defaults to “n”.
- Returns
The Chepy object.
- Return type
- from_nato(delimiter: Optional[str] = None, join_by: str = '') DataFormatT ¶
Translate NATO phoentic to words
- Parameters
delimiter (str, optional) – Delimiter to split on. Defaults to ‘ ‘.
join_by (str, optional) – Join result by. Defaults to ‘’.
- Returns
The Chepy object
- Return type
- from_octal(delimiter: str = None, join_by: str = '') DataFormatT ¶
Convert a list of octal numbers to string
- Parameters
delimiter (str, optional) – Delimiter. Defaults to None.
join_by (str, optional) – Join by. Defaults to “”.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("141 142").from_octal().o "ab"
- from_pickle(trust: bool = False) DataFormatT ¶
Deserialize pickle data
- Parameters
trust (bool, optional) – As this can lead to code execution, this is a safety net and needs to be set to True. Defaults to False.
- Returns
The Chepy object.
- Return type
- from_punycode() DataFormatT ¶
Decode to punycode
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy(b"mnchen-3ya").from_punycode().o "münchen"
- from_quoted_printable() DataFormatT ¶
From quoted printable
- Returns
The Chepy object.
- Return type
- from_unix_timestamp(format: str = '%c', utc: bool = False) DateTimeT ¶
Convert UNIX timestamp to datetime
- Parameters
format – Format to use for datetime.strftime()
utc – Whether to use UTC or local timezone
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("1573426649").from_unix_timestamp() "Sun Nov 10 17:57:29 2019"
- from_upside_down(reverse: bool = False)¶
From upside down
- Parameters
reverse (bool, optional) – Reverse order. Defaults to False.
- Returns
The Chepy object.
- Return type
- from_url_encoding() DataFormatT ¶
Converts URI/URL percent-encoded characters back to their raw values.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("https://google.com/%3Flol%3Dsome+data%26a%3D1").from_url_encoding().o "https://google.com/?lol=some data&a=1"
- from_uuencode(header: str = '-') DataFormatT ¶
From UUEncode
- Parameters
header (str) – header
- Returns
The Chepy object.
- Return type
- generate_ecc_keypair(curve: Literal['p256', 'p384', 'p521'] = 'p256', format: Literal['PEM', 'DER'] = 'PEM') PublickeyT ¶
Generate RSA key pair
- Parameters
curve (Literal[, optional) – Curve for keys. Defaults to p256.
format (Literal[, optional) – Output format type. Defaults to ‘PEM’.
- Returns
The Chepy object.
- Return type
- generate_rsa_keypair(bits: int = 1024, format: Literal['PEM', 'DER'] = 'PEM', passphrase: str = None) PublickeyT ¶
Generate RSA key pair
- Parameters
bits (int, optional) – Length of keys. Defaults to 1024.
format (Literal[, optional) – Output format type. Defaults to ‘PEM’.
passphrase (str, optional) – Passphrase for keys. Defaults to None.
- Returns
The Chepy object.
- Return type
- generate_uuid() OtherT ¶
Generate v4 UUID
Generates an RFC 4122 version 4 compliant Universally Unique Identifier (UUID), also known as a Globally Unique Identifier (GUID). A version 4 UUID relies on random numbers
- Returns
A random UUID
- Return type
str
Examples
>>> Chepy('').generate_uuid() 92644a99-632a-47c1-b169-5a141172924b
- get_by_index(*indexes: int)¶
Get an item by specifying an index. If only one index is specified, the obj is return else a new list is returned
- Parameters
*indexes (int) – Index numbers to get.
- Returns
The Chepy object.
- Return type
- get_by_key(*keys: str, py_style: bool = False, split_key: str = '.')¶
This method support json keys support.
- Parameters
keys (Tuple[Union[Hashable, None]]) – Keys to extract.
split_key (str, optional) – Split nested keys. Defaults to “.”
nested (bool, optional) – If the specified keys are nested. Supports array indexing. Defaults to True
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy({"a":{"b": "c"}}).get_by_key('a.b') >>> 'c'
- get_register(key: str) Union[str, bytes] ¶
Get a value from registers by key
- Parameters
key (str) – Key
- Raises
ValueError – If key does not exist
- Returns
Value of register
- Return type
Union[str, bytes]
- get_ssl_cert(port: int = 443) NetworkingT ¶
Get the server side SSL certificate for a domain
- Parameters
port (int, optional) – Server port. Defaults to 443.
- Returns
The Chepy object
- Return type
Examples
>>> Chepy('google.com').get_ssl_cert().o { 'subject': { 'commonName': '*.google.com', 'organizationName': 'Google LLC', ... 'caIssuers': ('http://pki.goog/gsr2/GTS1O1.crt',), 'crlDistributionPoints': ('http://crl.pki.goog/GTS1O1.crl',) }
- get_state(index: int) Any ¶
Returns the value of the specified state.
This method does not chain with other methods of Chepy
- Parameters
index (int) – The index of the state
- Returns
Any value that is in the specified state
- Return type
Any
- github_to_raw() LinksT ¶
Convert a github link to raw github link
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("https://github.com/securisec/chepy/blob/master/README.md").github_to_raw() 'https://raw.githubusercontent.com/securisec/chepy/master/README.md'
- google_search_ei_to_epoch() LinksT ¶
Convert a google search ei query param to epoch
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("Bh8hYqykHc64mAXkkoTgCg==").google_search_ei_to_epoch() 1646337798
- gpp_decrypt()¶
Decrypt Group Policy Preferences (GPP) password
- Returns
The Chepy object.
- Return type
- gzip_compress(file_name: str = None) CompressionT ¶
Create a gz archive with data from state
- Parameters
file_name (str, optional) – File name for file inside zip archive. Defaults to None.
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("some data").gzip_compress() >>> c.write("/some/path/file.zip", as_binary=True)
- gzip_decompress() CompressionT ¶
Decompress a gzip archive
- Returns
The Chepy object.
- Return type
- hex_to_bytes() DataFormatT ¶
Hex to bytes hex
Converts a hex string to its bytes form. Example: 41 becomes x41
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("ab00").hex_to_bytes().o b"\xab\x00"
- hex_to_int() DataFormatT ¶
Converts hex into its integer representation
- Returns
The Chepy object.
- Return type
Examples
Chepy works with hex characters that start with a 0x
>>> Chepy("0x123").hex_to_int().out 291
Without 0x in the hex
>>> Chepy("123").hex_to_int().out 291
- hex_to_str(ignore: bool = False) DataFormatT ¶
Decodes a hex string to ascii ignoring any decoding errors
- Parameters
ignore (bool, optional) – Ignore errors, by default False
- Returns
The Chepy object.
- Return type
Examples
To ignore UnicodeDecode errors, set ignore to True >>> Chepy(“4100”).hex_to_str(ignore=True).o “A"
- hmac_hash(key: bytes = b'', digest: str = 'sha1') HashingT ¶
Get HMAC hash
HMAC hash the state
Keyed-Hash Message Authentication Codes (HMAC) are a mechanism for message authentication using cryptographic hash functions.
- Parameters
key (bytes, optional) – Starting key for the hash, by default b’’
digest (str, optional) – The digest type, by default “sha1”. Possible values are md5, sha1, sha256 and sha512
- Returns
The Chepy object.
- Return type
- Raises
TypeError – If key is not in bytes
TypeError – If not a valid/allowed digest type
- http_request(method: str = 'GET', params: dict = {}, json: dict = None, headers: dict = {}, cookies: dict = {})¶
Make a http/s request
Make a HTTP/S request and work with the data in Chepy. Most common http methods are supported; but some methods may not provide a response body.
- Parameters
method (str, optional) – Request method. Defaults to ‘GET’.
params (dict, optional) – Query Args. Defaults to {}.
json (dict, optional) – Request payload. Defaults to None.
headers (dict, optional) – Headers for request. Defaults to {}.
cookies (dict, optional) – Cookies for request. Defaults to {}.
- Raises
NotImplementedError – If state is not a string or dictionary
requests.RequestException – If response status code is not 200
- Returns
A dictionary containing body, status and headers. The Chepy object.
- Return type
Examples
By default, this methed with make a GET request, But supports most common methods.
>>> c = Chepy("http://example.com").http_request() >>> c.get_by_key("headers")
This method can also be used to make more complex requests by specifying headers, cookies, body data etc.
>>> c = Chepy("https://en4qpftrmznwq.x.pipedream.net") >>> c.http_request( >>> method="POST", >>> headers={"My-header": "some header"}, >>> json={"some": "data"} >>> ) >>> print(c.get_by_key("body")) {"success": true}
- huffman_decode(huffman_codes: Dict[str, str]) EncryptionEncodingT ¶
Huffman decode
- Parameters
huffman_codes (Dict[str, str]) – Huffman codes as a dict
- Returns
The Chepy object.
- Return type
- increment_bytes(n: int) DataFormatT ¶
Loop through each byte and increment
- Parameters
n (int) – increment by.
- Returns
The Chepy object.
- Return type
- int_to_base(base: Union[int, str]) AritmeticLogicT ¶
Convert the state to a different base
- Parameters
base (int) – Base to convert to
- Returns
The Chepy object.
- Return type
- int_to_hex() DataFormatT ¶
Converts an integer into its hex equivalent
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy(101).int_to_hex().o "65"
- int_to_ip() NetworkingT ¶
Convert an integer to an IP address
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy(3232235777).int_to_ip().o
- int_to_str() DataFormatT ¶
Converts an integer into a string
- Returns
The Chepy object.
- Return type
- ip_to_int() NetworkingT ¶
Convert an integer to an IP address
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy(3232235777).int_to_ip().o
- javascript_comments() ExtractorsT ¶
Extract javascript comments
Some false positives is expected because of inline // comments
- Returns
The Chepy object.
- Return type
- join(join_by: Union[str, bytes] = '') DataFormatT ¶
Join a list with specified character
- Parameters
join_by (Union[str, bytes], optional) – What to join with. Defaults to “”
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy(["a", "b", "c"]).join_list(":").o "a:b:c"
- json_to_dict() DataFormatT ¶
Convert a JSON string to a dict object
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy('{"some": "data", "a": ["list", 1, true]}').json_to_dict().o { "some": "data", "a": ["list", 1, True], }
- json_to_yaml() DataFormatT ¶
Convert a json string to yaml structure
- Returns
The Chepy object.
- Return type
- jwt_decode() EncryptionEncodingT ¶
Decode a JWT token. Does not verify
- Returns
The Chepy object.
- Return type
- jwt_sign(secret: str, algorithms: str = 'HS256') EncryptionEncodingT ¶
Sign a json/dict object in JWT
- Parameters
secret (str) – Required. Secret to sign with
algorithms (str, optional) – Signing algorithm. Defaults to “HS256”.
- Returns
The Chepy object.
- Return type
- jwt_token_generate_embedded_jwk(private_key_pem: str, private_key_passphrase: str = None, headers: dict = {}, alg: str = 'RS256') EncryptionEncodingT ¶
Generate a JWT token with an embedded JWK
- Parameters
private_key_pem (str) – Private key to sign token
private_key_passphrase (str, optional) – Private key passphrase. Defaults to None.
headers (dict, optional) – Token headers. Defaults to {}.
alg (str, optional) – Token algorithm. Defaults to “RS256”.
- Returns
The Chepy object.
- Return type
- jwt_token_generate_none_alg(headers: Dict[str, Any] = {}) EncryptionEncodingT ¶
Generate a jwt token with none algorithm
- Parameters
headers (Dict[str, Any], optional) – Headers. alg key will be overwritten. Defaults to {}.
- Returns
The Chepy object.
- Return type
- jwt_verify(secret: str, algorithm: list = ['HS256']) EncryptionEncodingT ¶
Verify JWT token
- Parameters
secret (str) – Required. Secret key for token
algorithm (list, optional) – Array of valid algorithms. Defaults to [“HS256”]
- Returns
The Chepy object.
- Return type
- length() DataFormatT ¶
Get the length of the current state as string
- Returns
The Chepy object.
- Return type
- list_to_str(join_by: Union[str, bytes] = ' ') DataFormatT ¶
Join an array by join_by
- Parameters
join_by (Union[str, bytes], optional) – String character to join by, by default ‘ ‘
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy(["a", "b", "c"]).list_to_str(",").o "a,b,c"
- load_buffer(index: int)¶
Load the specified buffer into state
- Parameters
index (int) – Index key of an existing buffer
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("A").save_buffer() >>> # this saves the current value of state to a new buffer >>> c.to_hex() >>> # operate on a state, in this case, convert to hex. >>> c.state "41" >>> c.buffers {0: "A"} >>> c.load_buffer(0) >>> # loads the content of the buffer back into the current state. >>> c.state "A"
- load_command()¶
Run the command in state and get the output
- Returns
The Chepy object.
- Return type
Examples
This method can be used to interface with the shell and Chepy directly by ingesting a commands output in Chepy.
>>> c = Chepy("ls -l").shell_output().o test.html ... test.py
- load_dir(pattern: str = '*')¶
Load all file paths in a directory
- Parameters
pattern (str, optional) – File pattern to match. Defaults to “*”.
- Returns
The Chepy object.
- Return type
- load_file(binary_mode: bool = False, encoding: Optional[str] = None)¶
If a path is provided, load the file
- Parameters
binary_mode (bool, optional) – Force load in binary mode.
encoding (Union[str, None], optional) – Encoding for string.
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("/path/to/file") >>> # at the moment, the state only contains the string "/path/to/file" >>> c.load_file() # this will load the file content into the state
- load_from_url(method: str = 'GET', params: dict = {}, json: dict = None, headers: dict = {}, cookies: dict = {})¶
Load binary content from a url
Most common http methods are supported; but some methods may not provide a response body.
- Parameters
method (str, optional) – Request method. Defaults to ‘GET’.
params (dict, optional) – Query Args. Defaults to {}.
json (dict, optional) – Request payload. Defaults to None.
headers (dict, optional) – Headers for request. Defaults to {}.
cookies (dict, optional) – Cookies for request. Defaults to {}.
- Raises
NotImplementedError – If state is not a string or dictionary
requests.RequestException – If response status code is not 200
- Returns
A bytearray of the response content. The Chepy object.
- Return type
Examples
By default, this methed with make a GET request, But supports most common methods.
>>> c = Chepy("http://example.com/file.png").load_from_url() >>> b'\x89PNG...'
- load_recipe(path: str)¶
Load and run a recipe
- Parameters
path (str) – Path to recipe file
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("some data").load_recipe("/path/to/recipe").out NzM2ZjZkNjUyMDY0NjE3NDYx
- loop(iterations: int, callback: str, args: dict = {})¶
Loop and apply callback n times
- Parameters
iterations (int) – Number of iterations to loop
callback (str) – The Chepy method to loop over
args (dict, optional) – Optional arguments for the callback. Defaults to {}.
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("VmpGb2QxTXhXWGxTYmxKV1lrZDRWVmx0ZEV0alZsSllaVWRHYWxWVU1Eaz0=") >>> c.loop(iterations=6, callback='hmac_hash', args={'key': 'secret'}) securisec
- loop_dict(keys: list, callback: str, args: dict = {})¶
Loop over a dictionary and apply the callback to the value
- Parameters
keys (list) – List of keys to match. If in cli, dont use spaces.
callback (str) – Chepy method as string
args (dict, optional) – Dictionary of args. If in cli, dont use spaces. Defaults to {}.
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy({'some': 'hahahaha', 'lol': 'aahahah'}) >>> c.loop_dict(['some'], 'hmac_hash', {'key': 'secret'}).o {'some': '99f77ec06a3c69a4a95371a7888245ba57f47f55', 'lol': 'aahahah'}
We can combine loop_list and loop_dict to loop over a list of dictionaries.
>>> data = [{"some": "val"}, {"some": "another"}, {"lol": "lol"}, {"another": "aaaa"}] >>> c = Chepy(data) >>> c.loop_list("loop_dict", {"keys": ["some", "lol"], "callback": "to_upper_case"}) [ {"some": "VAL"}, {"some": "ANOTHER"}, {"lol": "LOL"}, {"another": "aaaa"}, ]
- loop_list(callback: str, args: dict = {})¶
Loop over an array and run a Chepy method on it
- Parameters
callback (str) – Chepy method as string
args (dict, optional) – Dictionary of args. If in cli, dont use spaces. Defaults to {}.
- Returns
The Chepy object
- Return type
Examples
This method is capable of running a callable from either a string, or a chepy method.
>>> c = Chepy(["an", "array"]) >>> c.loop_list('to_hex').loop_list('hmac_hash', {'key': 'secret'}) ['5cbe6ca2a66b380aec1449d4ebb0d40ac5e1b92e', '30d75bf34740e8781cd4ec7b122e3efd8448e270']
- ls47_decrypt(password: str, padding: int = 10) EncryptionEncodingT ¶
LS47 decrypt
- Parameters
password (str) – password
padding (int, optional) – Padding. Defaults to 10.
- Returns
The Chepy object.
- Return type
- ls47_encrypt(password: str, padding: int = 10, signature: str = '') EncryptionEncodingT ¶
LS47 encrypt
- Parameters
password (str) – password
padding (int, optional) – Padding. Defaults to 10.
signature (str, optional) – Signature to prepend. Defaults to ‘’.
- Returns
The Chepy object.
- Return type
- lz77_compress(window_size: int = 13, lookahead_buffer_size: int = 6)¶
To LZ77 compression
- Parameters
window_size (int, optional) – Window size. Defaults to 13.
lookahead_buffer_size (int, optional) – Lookahead. Defaults to 6.
- Returns
The Chepy object.
- Return type
- lz77_decompress(window_size: int = 13, lookahead_buffer_size: int = 6)¶
From LZ77 compression
- Parameters
window_size (int, optional) – Window size. Defaults to 13.
lookahead_buffer_size (int, optional) – Lookahead. Defaults to 6.
- Returns
The Chepy object.
- Return type
- lzma_decompress() CompressionT ¶
Decompress lzma compressed data
- Returns
The Chepy object.
- Return type
- md5() HashingT ¶
Get MD5 hash
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("A").md5().out "7fc56270e7a70fa81a5935b72eacbe29"
- mean() AritmeticLogicT ¶
Calculate the mean of the state
- Returns
The Chepy object.
- Return type
- median() AritmeticLogicT ¶
Calculate the median of the state
- Returns
The Chepy object.
- Return type
- minify_json() CodeTidyT ¶
Minify JSON string
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("/path/to/file.json").load_file() >>> print(c.minify_json())
- monoalphabetic_substitution(mapping: Dict[str, str] = {}) EncryptionEncodingT ¶
Monoalphabetic substitution. Re-map characters
- Parameters
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
The Chepy object
- Return type
- multiply(n: int) AritmeticLogicT ¶
Multiply a number to the state
- Parameters
n (int) – Number to multiply with
- Returns
The Chepy object.
- Return type
- normalize_hex(is_bytearray=False) DataFormatT ¶
Normalize a hex string
Removes special encoding characters from a hex string like %, 0x, , :, ;, n and rn
- Parameters
is_bytearray (bool, optional) – Set to True if state is a bytearray
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("41:42:CE").normalize_hex().o "4142CE" >>> Chepy("0x410x420xce").normalize_hex().o "4142ce"
- pad(width: int, direction: str = 'left', char: str = ' ') UtilsT ¶
Pad string with a character
- Parameters
width (int) – Required. Total length of string. The padding is calculated from the length of state minus width.
direction (str, optional) – Padding direction. left or right. Defaults to ‘left’.
char (str, optional) – Char to fill with. Defaults to ‘ ‘.
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("lol").pad(5, char="a") lol # this is because "lol" is len 3, and padding is 5 - 2, which is 2, so no padding is added >>> c = Chepy("lol").pad(8, char="a") lolaa # 8 - 3 so the output is padded for 5 chars >>> c = Chepy("lol").pad(8, direction="right", char="a") aalol
- parse_csv() DataFormatT ¶
Parse a csv file. Returns a list of dict objects.
- Returns
The Chepy object.
- Return type
- parse_ip_range() NetworkingT ¶
Enumerate IP address in a CIDR range
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("10.10.10.1/24").parse_ip_range().o [ "10.10.10.1", "10.10.10.2, ... "10.10.10.254" ]
- parse_ipv6() NetworkingT ¶
Get longhand and shorthand of IPv6
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("2001:4860:4860::8888").parse_ipv6().o { "long": "2001:4860:4860:0000:0000:0000:0000:8888", "short": "2001:4860:4860::8888", }
- parse_public_pem() PublickeyT ¶
Parse pubkey PEM to get n and e
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("tests/files/public.pem").load_file().parse_public_pem().get_by_key("e").o 65537
- parse_sqlite(query: str) DataFormatT ¶
Parse sqlite db and run queries against it. Returns an array of dict objects with column as key and value
- Parameters
query (str) – SQL Query
- Returns
The Chepy object.
- Return type
- parse_uri() NetworkingT ¶
Parse a URI
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("http://example.com/resource?foo=bar#fragment").parse_uri().o { "scheme": "http", "location": "example.com", "path": "/resource", "params": "", "query": {"foo": ["bar"]}, "fragment": "fragment", }
- parse_x509_der_hex() PublickeyT ¶
Parse X509 cert in DER format
X.509 is an ITU-T standard for a public key infrastructure (PKI) and Privilege Management Infrastructure (PMI). It is commonly involved with SSL/TLS security.<br><br>This operation displays the contents of a certificate in a human readable format, similar to the openssl command line tool.
- Returns
A Chepy object.
- Return type
- parse_x509_pem() PublickeyT ¶
Parse X509 cert in PEM format
X.509 is an ITU-T standard for a public key infrastructure (PKI) and Privilege Management Infrastructure (PMI). It is commonly involved with SSL/TLS security. This operation displays the contents of a certificate in a human readable format, similar to the openssl command line tool.
- Returns
A Chepy object.
- Return type
Examples
>>> Chepy(path).load_file().parse_x509_pem().o { "version": 0, ... "after": b"20201101152508Z", "issuer": { "C": "US", ... "email": "none@email.com", }, "subject": { "C": "US", ... "email": "none@email.com", }, "pubkey": {"bits": 1024}, }
- password_hashing(format: str, **kwargs: Any) HashingT ¶
Hash the state with various password hashing algorithms
- Parameters
format (str) – Hash state with password algorithms
- Returns
The Chepy object.
- Return type
- pastebin_to_raw() LinksT ¶
Convert a pastebin link to raw pastebin link
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("https://pastebin.com/abCD").pastebin_to_raw() 'https://pastebin.com/raw/abCD'
- pem_to_der_hex() PublickeyT ¶
Convert PEM cert to DER format
Converts PEM (Privacy Enhanced Mail) format to a hexadecimal DER (Distinguished Encoding Rules) string.
- Returns
The Chepy object.
- Return type
- pick(*values: Any)¶
Only pick specified values from the state. Works on strings, bytes, lists and dicts
- Raises
TypeError – If state does not contain valid data
- Returns
The chepy object.
- Return type
- plugins(enable: str) None ¶
Use this method to enable or disable Chepy plugins.
Valid options are true or false. Once this method completes, it does call sys.exit().
- Parameters
enable (str) – Set to true or false
- Returns
None
- power(n: int) AritmeticLogicT ¶
Convert state to the n power of
- Parameters
n (int) – Exponent
- Returns
The Chepy object.
- Return type
- prefix(data: bytes)¶
Add a prefix to the data in state. The state is converted to bytes
- Parameters
data (bytes) – Data to add
- Returns
The Chepy object.
- Return type
- pretty(indent: int = 2)¶
Prettify the state.
- Parameters
indent (int, optional) – Indent level. Defaults to 2.
- Returns
The Chepy object.
- Return type
- public_from_x509() PublickeyT ¶
Get public key from x509 certificate
- Returns
The Chepy object.
- Return type
- rabbit(key: str, iv: Union[None, str] = None) EncryptionEncodingT ¶
Rabbit encryption/decryption
- Parameters
key (str) – Key
iv (Union[None,str], optional) –
Defaults to None.
- Returns
The Chepy object.
- Return type
- railfence_decode(key=2, offset=0) EncryptionEncodingT ¶
Decode railfence
- Parameters
key (int, optional) – Key. Should be equal or larger than data. Defaults to 2.
offset (int, optional) – Offset. Defaults to 0.
- Returns
The Chepy object.
- Return type
- railfence_encode(key=2, offset=0) EncryptionEncodingT ¶
Encode to railfence
- Parameters
key (int, optional) – Key. Should be equal or larger than data. Defaults to 2.
offset (int, optional) – Offset. Defaults to 0.
- Returns
The Chepy object.
- Return type
- rc4_decrypt(key: str, key_format: str = 'hex') EncryptionEncodingT ¶
Decrypt raw state with RC4
- Parameters
key (str) – Required. Secret key
key_format (str, optional) – Key format. Defaults to “hex”.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("9e59bf79a2c0b7d253").hex_to_str().rc4_decrypt("secret").o b"some data"
- rc4_encrypt(key: str, key_format: str = 'hex') EncryptionEncodingT ¶
Encrypt raw state with RC4
- Parameters
key (str) – Required. Secret key
key_format (str, optional) – Key format. Defaults to “hex”.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("some data").rc4_encrypt("736563726574").o b"9e59bf79a2c0b7d253"
- refang_ip() NetworkingT ¶
Refangs an IP address
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("127[.]0[.]0[.]1").refang_ip().o "127.0.0.1"
- refang_url() NetworkingT ¶
Refangs a URL so that it is clickable
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("hxxps://app[.]google[.]com/?lol=some data&a=1").refang_url().o "https://app.google.com/?lol=some data&a=1"
- regex_search(pattern: str, is_bytes: bool = False, ignore_case: bool = False, multiline: bool = False, dotall: bool = False, unicode: bool = False, extended: bool = False) UtilsT ¶
Regex search on current data. State will be an array of matches.
- Parameters
pattern (str) – Required. The regex pattern to search by
is_bytes (bool, optional) – Treat the pattern and state as bytes. Defaults to False.
ignore_case (bool, optional) – Set case insensitive flag. Defaults to False.
multiline (bool, optional) – ^/$ match start/end. Defaults to False.
dotall (bool, optional) – . matches newline. Defaults to False.
unicode (bool, optional) – Match unicode characters. Defaults to False.
extended (bool, optional) – Ignore whitespace. Defaults to False.
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("loLolololoL") >>> c.regex_search("ol", ignore_case=True)
- regex_to_str(all_combo: bool = False) UtilsT ¶
Convert a regex to a matching string
- Parameters
all_combo (bool, optional) – Generate all combos that match regex. Defaults to False.
- Returns
The Chepy object.
- Return type
- register(pattern: Union[str, bytes], ignore_case: bool = False, multiline: bool = False, dotall: bool = False, unicode: bool = False, extended: bool = False)¶
Extract data from the input and store it in registers. Regular expression capture groups are used to select the data to extract.
- Parameters
pattern (Union[str, bytes]) – Required. The regex pattern to search by
ignore_case (bool, optional) – Set case insensitive flag. Defaults to False.
multiline (bool, optional) – ^/$ match start/end. Defaults to False.
dotall (bool, optional) – . matches newline. Defaults to False.
unicode (bool, optional) – Match unicode characters. Defaults to False.
extended (bool, optional) – Ignore whitespace. Defaults to False.
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("hello world") >>> c.register("(hello)\s(world)") >>> c._registers {'$R0': 'hello', '$R1': 'world'}
- remove_diacritics() LanguageT ¶
Replaces accented characters latin character equivalent.
- Returns
The Chepy object.
- Return type
- remove_nonprintable(replace_with: Union[str, bytes] = b'') DataFormatT ¶
Remove non-printable characters from string.
- Parameters
replace_with (bytes, optional) – Replace non-printable characters with this. Defaults to ‘’.
- Returns
The Chepy object.
- Return type
- remove_nullbytes() UtilsT ¶
Remove null x00 byes from binary data
- Returns
The Chepy object.
- Return type
- remove_whitespace(spaces: bool = True, carriage_return: bool = True, line_feeds: bool = True, tabs: bool = True, form_feeds: bool = True)¶
Remove whitespace from a string
- Parameters
spaces (bool, optional) – Remove spaces. Defaults to True.
carriage_return (bool, optional) – Remove carriage return r. Defaults to True.
line_feeds (bool, optional) – Remove line feeds n. Defaults to True.
tabs (bool, optional) – Temove tabs t. Defaults to True.
form_feeds (bool, optional) – Remove form feeds f. Defaults to True.
- Returns
The Chepy object.
- Return type
- reverse(count: int = 1) UtilsT ¶
Reverses a string
- Parameters
count (int, optional) – Reverse by the number of characters indicated in count. Defaults to 1.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("abcdefg").reverse().out "gfedcba"
- rot_13(amount=13, rotate_lower=True, rotate_upper=True, rotate_numbers=False) EncryptionEncodingT ¶
Rot 13
- Parameters
amount (int, optional) – Rotate amount. Defaults to 13.
rotate_lower (bool, optional) – Rotate lowercase. Defaults to True.
rotate_upper (bool, optional) – Rotate uppercase. Defaults to True.
rotate_numbers (bool, optional) – Rotate numbers. Defaults to False.
- Returns
The Chepy object.
- Return type
- rot_47(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.
- Parameters
rotation (int, optional) – Amount to rotate by. Defaults to 14.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("some").rot_47().out b"D@>6"
- rot_47_bruteforce() EncryptionEncodingT ¶
ROT 47 bruteforce
- Returns
The Chepy object.
- Return type
- rotate(rotate_by: int) EncryptionEncodingT ¶
Rotate string by provided number
- Parameters
rotate_by (int) – Required. Number to rotate by
- Returns
The Chepy object.
- Return type
Examples
In this example, we will rotate by 20
>>> Chepy("some data").rotate(20).out "migy xunu"
- rotate_bruteforce() EncryptionEncodingT ¶
Brute force rotation from 1 to 26. Returned value is a dict where key is the rotation count.
- Returns
The Chepy object.
- Return type
Examples
In this example, we will rotate by 20
>>> Chepy('uryyb').rotate_bruteforce() { '1': 'vszzc', '2': 'wtaad', ... '13': 'hello', ... }
- rotate_left(radix: int = 1, carry: bool = False) DataFormatT ¶
Rotate left
- Parameters
radix (int, optional) – Radix. Defaults to 1.
carry (bool, optional) – Carry. Defaults to False.
- Returns
The Chepy object.
- Return type
- rotate_right(radix: int = 1, carry: bool = False) DataFormatT ¶
Rotate right
- Parameters
radix (int, optional) – Radix. Defaults to 1.
carry (bool, optional) – Carry. Defaults to False.
- Returns
The Chepy object.
- Return type
- rsa_decrypt(private_key: str, is_file: bool = True, passphrase: str = None, cipher: Literal['OAEP', 'PKCS'] = 'OAEP') EncryptionEncodingT ¶
Decrypt data with RSA Private key in PEM format
- Parameters
private_key (str) – Path to Private key
is_file (bool) – If supplied argument is a PEM file path. Defaults to false
passphrase (str) – passphrase. Defaults to None
cipher (str) – Cipher type. Defaults to OAEP
- Returns
The Chepy object
- Return type
- rsa_encrypt(public_key: str, is_file: bool = True, passphrase: str = None, cipher: Literal['OAEP', 'PKCS'] = 'OAEP') EncryptionEncodingT ¶
Encrypt data with RSA Public key in PEM format
- Parameters
public_key (str) – Path to Public key
is_file (bool) – If supplied argument is a PEM file path. Defaults to false
passphrase (str) – passphrase. Defaults to None
cipher (str) – Cipher type. Defaults to OAEP
- Returns
The Chepy object
- Return type
- rsa_private_pem_to_jwk() EncryptionEncodingT ¶
Convert RSA PEM private key to jwk format
- Returns
The Chepy object.
- Return type
- rsa_public_key_from_jwk() EncryptionEncodingT ¶
Generate RSA public key in PEM format from JWK
- Raises
AssertionError – If n or e not found
- Returns
The Chepy object.
- Return type
- rsa_sign(private_key: str, is_file: bool = True, passphrase: str = None, hash_format: Literal['SHA256', 'SHA512', 'SHA1', 'MD5', 'SHA384'] = 'SHA256') EncryptionEncodingT ¶
Sign data in state with RSA Private key in PEM format
- Parameters
private_key (str) – Private key
is_file (bool) – If supplied argument is a PEM file path. Defaults to false
passphrase (str) – passphrase. Defaults to None
hash_format (str) – hash type. Defaults to SHA256
- Returns
The Chepy object
- Return type
- rsa_verify(signature: bytes, public_key: str, is_file: bool = True, passphrase: str = None, hash_format: Literal['SHA256', 'SHA512', 'SHA1', 'MD5', 'SHA384'] = 'SHA256') EncryptionEncodingT ¶
Verify data in state with RSA Public key in PEM format
- Parameters
signature (bytes) – The signature as bytes
public_key (str) – Path to Private key
is_file (bool) – If supplied argument is a PEM file path. Defaults to false
passphrase (str) – passphrase. Defaults to None
hash_format (str) – Cipher type. Defaults to SHA256
- Returns
The Chepy object
- Return type
- run_recipe(recipes: List[Mapping[str, Union[str, Mapping[str, Any]]]])¶
Run a recipe on the state. All arguments including optional needs to be specified for a recipe.
- Parameters
recipes (List[Mapping[str, Union[str, Mapping[str, Any]]]]) – An array of recipes. Recipes are in the format {‘function’: ‘function_name’, ‘args’: {‘arg_name’: ‘arg_val’}}
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy('bG9sCg==').run_recipe([{"function":"base64_decode","args":{"custom":None}}]]) >>> lol In this example, we are calling the base64 decode method on the state.
- run_script(path: str, save_state: bool = False)¶
Inject and run a custom script on the state. The custom script must have a function called cpy_script which must take one argument. The state is passed as the argument.
- Parameters
path (str) – Path to custom script
save_state (bool, optional) – Save script output to the state. Defaults to False.
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("A").to_hex().run_script('tests/files/script.py', True) b'4141'
- save_buffer(index: int = None)¶
Save current state in a buffer
Buffers are temporary holding areas for anything that is in the state. The state can change, but the buffer does not. Can be chained with other methods. Use in conjunction with load_buffer to load buffer back into the state.
- Parameters
index (int, optional) – The index to save the state in, defaults to next index if None
- Returns
The Chepy object.
- Return type
- save_recipe(path: str)¶
Save the current recipe
A recipe will be all the previous methods called on the chepy instance along with their args
- Parameters
path (str) – The path to save the recipe
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("some data").to_hex().base64_encode() >>> c.save_recipe("/path/to/recipe) >>> c.out NzM2ZjZkNjUyMDY0NjE3NDYx
- scrypt_hash(salt: str = '', key_length: int = 64, N: int = 14, r: int = 8, p: int = 1)¶
Get Scrypt hash
- Parameters
salt (str, optional) – A string of characters that modifies the hash. Defaults to “”.
key_length (int, optional) – number of bytes to use when autogenerating new salts. Defaults to 64.
N (int, optional) – CPU/memory cost parameter. Defaults to 14.
r (int, optional) – The blocksize parameter. Defaults to 8.
p (int, optional) – Parallelization parameter;. Defaults to 1.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("abc").scrypt_hash(salt="", key_length=16).out "f352f3374cf4e344dde4108b96985248"
- search(pattern: Union[str, bytes]) SearchT ¶
Search. Group matches are returned as tuples.
- Parameters
pattern (Union[str, bytes]) – Bytes pattern to search
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("abcdefg123 and again abcdefg123").search("abc(de)fg(12)(3)").o [('abcdefg123', 'de', '12', '3'), ('abcdefg123', 'de', '12', '3')]
- search_ctf_flags(prefix: str, postfix: str = '.+?\\{*\\}') SearchT ¶
Search CTF style flags.
This by default assumes that the flag format is similar to something like picoCTF{some_flag} as an example.
- Parameters
prefix (str) – Prefix of the flag. Like picoCTF
postfix (str, optional) – Regex for the remainder of the flag. Defaults to ‘.+{.+}’.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("tests/files/flags").read_file().search_ctf_flags("pico").get_by_index(0) picoCTF{r3source_pag3_f1ag}
- search_dir(pattern: Union[bytes, str])¶
Search all files in a directory. Pattern is case insensitive
- Parameters
pattern (Union[bytes, str]) – regex to search
- Returns
The Chepy object.
- Return type
- search_list(pattern: Union[str, bytes]) SearchT ¶
Search all items in a list. List items are coerced into bytes first. Group matches are returned as tuples.
- Parameters
pattern (Union[str, bytes]) – Bytes pattern to search
- Returns
The Chepy object.
- Return type
- search_perl_unicode_props(lang: str) LanguageT ¶
Search using perl unicode properties. https://perldoc.perl.org/perluniprops#(%5Cd+)-in-the-info-column-gives-the-number-of-Unicode-code-points-matched-by-this-property.
- Parameters
lang (str) – Required. A string value identifying the language.
- Returns
The Chepy object.
- Return type
- search_private_key() SearchT ¶
Search varios private key headers
- Returns
The Chepy object.
- Return type
- search_slack_tokens() SearchT ¶
Search slack tokens
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("tests/files/flags").read_file().search_slack_tokens().get_by_index(0) xoxp...859
- select(start: int, end: int = None) DataFormatT ¶
Get an item by specifying an index
- Parameters
start (int) – Starting index number to get
end (int, optional) – Ending index number to get. If none specified, will be end of item. Defaults to None.
- Returns
The Chepy object.
- Return type
- select_every_n(n: int, start: int = 0) UtilsT ¶
Select every nth item from a list or string.
Index starts at 0
- Parameters
n (int) – n from 0
start (int) – starting position. Defaults to 0.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy(["a", 1, "lol", "b", True]).select_every_n(3) ["a", "b"]
- set_plugin_path(path: str) None ¶
Use this method to set the path for Chepy plugins.
- Parameters
path (str) – Path to plugins directory
- Returns
None
- set_register(key: str, val: Union[str, bytes])¶
Set the value of a register
- Parameters
key (str) – Key
val (Union[str, bytes]) – Value
- Returns
The Chepy object.
- Return type
- set_state(data: Any)¶
Set any arbitrary values in the current state
This method is simply changing the value of the instantiated state with an arbitrary value.
- Parameters
data (Any) – Any data type
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("some data") >>> print(c.state) some data >>> c.set_state("New data") >>> print(c.state) New data
- sha1() HashingT ¶
Get SHA1 hash
The SHA (Secure Hash Algorithm) hash functions were designed by the NSA. SHA-1 is the most established of the existing SHA hash functions and it is used in a variety of security applications and protocols. However, SHA-1’s collision resistance has been weakening as new attacks are discovered or improved.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("A").sha1().out "6dcd4ce23d88e2ee9568ba546c007c63d9131c1b"
- sha2_224() HashingT ¶
Get SHA2-224 hash
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("A").sha2_224().out "5cfe2cddbb9940fb4d8505e25ea77e763a0077693dbb01b1a6aa94f2"
- sha2_256() HashingT ¶
Get SHA2-256 hash
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("A").sha2_256().out "559aead08264d5795d3909718cdd05abd49572e84fe55590eef31a88a08fdffd"
- sha2_512() HashingT ¶
Get SHA2-512 hash
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("A").sha2_512().out 21b4f4bd9e64ed355c3eb676a28ebedaf6d8f17bdc365995b319097153044080516bd083bfcce66121a3072646994c8430cc382b8dc543e84880183bf856cff5
- sha2_512_truncate(truncate: int = 256) HashingT ¶
Get SHA2-512/bits hash
- Parameters
truncate (int, optional) – The bits to truncate by. Defaults to 256
- Returns
The Chepy object.
- Return type
- shake_128(size: int = 64) HashingT ¶
Get Shake-128 hash
Shake is an Extendable Output Function (XOF) of the SHA-3 hash algorithm, part of the Keccak family, allowing for variable output length/size.
- Parameters
size (int, optional) – How many bytes to read, by default 64
- Returns
The Chepy object.
- Return type
- shake_256(size: int = 64) HashingT ¶
Get Shake-256 hash
Shake is an Extendable Output Function (XOF) of the SHA-3 hash algorithm, part of the Keccak family, allowing for variable output length/size.
- Parameters
size (int, optional) – How many bytes to read, by default 64
- Returns
The Chepy object.
- Return type
- shuffle() UtilsT ¶
Shuffle the state if it is a list, string or bytes. The state is unchanged if any other types.
- Returns
The Chepy object
- Return type
- slice(start: int = 0, end: int = None) UtilsT ¶
Returns the specified slice
- Parameters
start (int, optional) – Start position. Defaults to 0.
end (int, optional) – End position. Defaults to None.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("some data").slice(3, 6).o "e d"
- sort_dict_key(reverse: bool = False) UtilsT ¶
Sort a dictionary by key
- Parameters
reverse (bool, optional) – Reverse sort order. Defaults to False.
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy({'z': 'string', 'a': True, 'zz': 1, 'aaa': {'bb': 'data'}, 'ccc': [1,'a']}) >>> c.sort_dict_key(reverse=True) {'zz': 1, 'z': 'string', 'ccc': [1, 'a'], 'aaa': {'bb': 'data'}, 'a': True}
- sort_dict_value(reverse=False) UtilsT ¶
Sort dictionary by value
- Parameters
reverse (bool, optional) – Reverse sort order. Defaults to False.
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy({'z': 'string', 'a': 'True', 'zz': '1', 'aaa': {'bb': 'data'}, 'ccc': [1,'a']}) >>> c.sort_dict_value() {'zz': '1', 'a': 'True', 'ccc': [1, 'a'], 'z': 'string', 'aaa': {'bb': 'data'}}
- sort_list(reverse: bool = False) UtilsT ¶
Sort a list
- Parameters
reverse (bool, optional) – In reverse order. Defaults to False.
- Raises
StateNotList – If state is not list
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy(["a", "b", "1", "2"]).sort_list().o ["1", "2", "a", "b"]
- split_by_char(delimiter: str = ' ') UtilsT ¶
Split a string by a delimiter
- Parameters
delimiter (str, optional) – Delimiter to split by. Defaults to ” “.
- Returns
The Chepy object.
- Return type
UtilsT
- split_by_n(n: int) UtilsT ¶
Split a string by n characters.
- Parameters
n (int) – n from 0
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("some string").split_by_n(2).o[2] " s"
- split_by_regex(pattern: str = '\n', trim=True) UtilsT ¶
Split a string by the given regex pattern
- Parameters
pattern (str, optional) – Pattern to split by. Defaults to ‘n’.
time (bool, optional) – Trim whitespace after split. Defaults to True
- Returns
The Chepy object.
- Return type
- split_chunks(chunk_size) UtilsT ¶
Split data in chunks
- Parameters
chunk_size (int) – Chunk size
- Returns
The Chepy object.
- Return type
- str_from_hexdump() DataFormatT ¶
Extract a string from a hexdump
- Returns
The Chepy object.
- Return type
- str_list_to_list() DataFormatT ¶
Convert a string list to a list
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("[1,2,'lol', true]").str_list_to_list().o [1, 2, "lol", True]
- str_to_dict() DataFormatT ¶
Convert string to a dictionary
- Returns
The Chepy object.
- Return type
- str_to_hex() DataFormatT ¶
Converts a string to a hex string
- Returns
The Chepy object.
- Return type
- str_to_list() DataFormatT ¶
Convert string to list
Converts the string in state to an array of individual characyers
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("abc").str_to_list().o ["a", "b", "c"]
- str_to_unicode(prefix: str = '\\u', all_chars: bool = False) LanguageT ¶
Convert unicode to str
- Parameters
prefix (str) – Prefix character.
all_chars (bool) – Force convert all chars to unicode.
- Returns
The Chepy object.
- Return type
- stringify(compact: bool = True) DataFormatT ¶
Stringify the state. This uses json.dumps unlike to_string
- Parameters
compact (bool, optional) – If the output should be compact. Defaults to True.
- Returns
The Chepy object.
- Return type
- strip(pattern: str, ignore_case=True) UtilsT ¶
Strip matched pattern
- Parameters
pattern (str) – Required. Pattern to search
ignore_case (bool, optional) – Case insensitive. Defaults to True.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("some some data").strip("some\s").o "data"
- strip_ansi() UtilsT ¶
Strip ANSI escape codes from string
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("[31mThis is a string[0m").strip_ansi().o "This is a string"
- sub(n: int) AritmeticLogicT ¶
SUB the input with the given key
- Parameters
n (int) – Number to subtract with
- Returns
The Chepy object.
- Return type
- subsection(pattern: Union[str, bytes], methods: List[Tuple[Union[str, object], dict]], group: int = 0)¶
Run specified methods over a subsection of the state. This method will always treat the state as bytes.
- Parameters
pattern (Union[str, bytes]) – Regex pattern to match against.
methods (List[Tuple[Union[str, object], dict]]) – Required. List of tuples. The first value of the tuple is the method name, the second value is a dictionary of arguments.
group (int, optional) – Matching group. Defaults to 0.
- Returns
_description_
- Return type
_type_
- substitute(x: str, y: str) DataFormatT ¶
Replace a subset of specified characters in the state.
- Parameters
x (str) – Chars to replace
y (str) – Chars to replace with
- Returns
The Chepy object.
- Return type
- substring(pattern: str, group: int = 0)¶
Choose a substring from current state as string
The preceding methods will only run on the substring and not the original state. Group capture is supported.
- Parameters
pattern (str) – Pattern to match.
group (int, optional) – Group to match. Defaults to 0.
- Returns
The Chepy object.
- Return type
- subtract(delimiter=None) AritmeticLogicT ¶
Subtracts a list of numbers. If an item in the string is not a number it is excluded from the list.
- Parameters
delimiter (str, optional) – Delimiter. Defaults to None.
- Returns
The Chepy object.
- Return type
- suffix(data: Union[str, bytes])¶
Add a suffix to the data in state. The state is converted to bytes
- Parameters
data (bytes) – Data to add
- Returns
The Chepy object.
- Return type
- swap_case() CodeTidyT ¶
Swap case in a string
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("SoMe TeXt").swap_case().o "sOmE tExT"
- swap_endianness(word_length: int = 4) DataFormatT ¶
Swap endianness.
- Parameters
word_length (int, optional) – Word length. Use 8 for big endian. Defaults to 4.
- Returns
The Chepy object.
- Return type
- swap_strings(by: int) DataFormatT ¶
Swap characters in string
- Parameters
by (int) – Number of bytes to swap
- Returns
The Chepy object
- Return type
- switch_state(index: int)¶
Switch current state by index
Same behaviour as change_state
- Parameters
index (int) – Index of new state
- Raises
TypeError – If specified index does not exist
- Returns
The Chepy object.
- Return type
- tar_compress(filename: str, mode: str = 'gz') CompressionT ¶
Compress the state into a tar compressed object.
- Parameters
filename (str) – A file name for the tar object
mode (str, optional) – Compression mode. Defaults to “gz”.
- Returns
The Chepy object.
- Return type
- tar_extract_all(mode: str = '') CompressionT ¶
Extract one file from inside a tar archive
- Parameters
mode (str, optional) – Mode to open tar file as. Defaults to “”.
- Returns
The Chepy object.
- Return type
- tar_extract_one(filename: str, mode: str = '') CompressionT ¶
Extract one file from inside a tar archive
- Parameters
filename (str) – Required. File name inside archive.
mode (str, optional) – Mode to open tar file as. Defaults to “”.
- Returns
The Chepy object.
- Return type
- tar_list_files(mode: str = '') CompressionT ¶
Get file information inside a tar archive
- Parameters
mode (str, optional) – Mode to open tar file as. Defaults to “”.
- Returns
The Chepy object.
- Return type
- to_bacon(A: Literal['A', '0'] = 'A', B: Literal['B', '1'] = 'B', complete: bool = True, join_by: Union[str, bytes] = b' ', invert: bool = False) DataFormatT ¶
Bacon encode
- Parameters
A (Literal['A', '0'], optional) – The A character. Defaults to ‘A’.
B (Literal['B', '1'], optional) – The B character. Defaults to ‘B’.
complete (bool, optional) – Use unique mapping for all characters. Defaults to True.
join_by (Union[str,bytes], optional) – Join output by. Defaults to b’ ‘.
invert (bool, optional) – Invert encoding. Defaults to False.
- Returns
The Chepy object.
- Return type
- to_base(radix: int = 36) DataFormatT ¶
Convert int to base
- Parameters
radix (int, optional) – Radix. Defaults to 36.
- Returns
The Chepy object.
- Return type
- to_base32() DataFormatT ¶
Encode as Base32
Base32 is a notation for encoding arbitrary byte data using a restricted set of symbols that can be conveniently used by humans and processed by computers. It uses a smaller set of characters than Base64, usually the uppercase alphabet and the numbers 2 to 7.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("some data").base32_encode().out.decode() "ONXW2ZJAMRQXIYI="
- to_base36(join_by: Union[str, bytes] = b' ') DataFormatT ¶
Encode to Base 36
- Parameters
join_by (Union[str, bytes], optional) – Join final output by. Defaults to b’ ‘.
- Returns
The Chepy object.
- Return type
- to_base58() DataFormatT ¶
Encode as Base58
Base58 is a notation for encoding arbitrary byte data using a restricted set of symbols that can be conveniently used by humans and processed by computers.This property encodes raw data into an ASCII Base58 string.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("some data").to_base58().out.decode() "2UDrs31qcWSPi"
- to_base62(alphabet: str = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz') DataFormatT ¶
Encode to base62
- Parameters
alphabet (str, optional) – Alphabet. Defaults to “0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz”.
- Returns
The Chepy object
- Return type
- to_base64(alphabet: str = 'standard') DataFormatT ¶
Encode as Base64
Base64 is a notation for encoding arbitrary byte data using a restricted set of symbols that can be conveniently used by humans and processed by computers.This property encodes raw data into an ASCII Base64 string.
- Parameters
alphabet (str, optional) – Provide a custom charset to base64 with. Valid values are: filename_safe, itoa64, radix_64, rot13, standard, unix_crypt, url_safe, xml, xxencoding, z64
- Returns
The Chepy object.
- Return type
Examples
>>> # To use a custom character set, use: >>> custom = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" >>> Chepy("Some data").to_base64(custom=custom).o b'IqxhNG/YMLFV'
- to_base85() DataFormatT ¶
Encode as Base58
Base85 is a notation for encoding arbitrary byte data using a restricted set of symbols that can be conveniently used by humans and processed by computers.This property decodes raw data into an ASCII Base58 string.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("some data").to_base85().out.decode() "F)Po,+Cno&@/"
- to_base91() DataFormatT ¶
Base91 encode Reference: https://github.com/aberaud/base91-python/blob/master/base91.py#L69
- Returns
The Chepy object.
- Return type
- to_binary(join_by: Union[str, bytes] = ' ', byte_length: int = 8) DataFormatT ¶
Convert string characters to binary
- Parameters
join_by (str, optional) – join_by. Defaults to ” “.
byte_length (int, optional) – Byte length. Defaults to 8.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("abc").to_binary().o b"01100001 01100010 01100011"
- to_braille() DataFormatT ¶
Convert text to six-dot braille symbols
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("secret message").to_braille().o "⠎⠑⠉⠗⠑⠞⠀⠍⠑⠎⠎⠁⠛⠑"
- to_bytes() DataFormatT ¶
Converts the data in state to bytes
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy({'some': 'val', 'kl': 1}).to_bytes().o b"{'some': 'val', 'kl': 1}"
- to_camel_case(ignore_space: bool = False) CodeTidyT ¶
Convert string to camel case
Converts the input string to camel case. Camel case is all lower case except letters after word boundaries which are uppercase. e.g. thisIsCamelCase
- Parameters
ignore_space (bool, optional) – Ignore space boundaries. Defaults to False.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("some Data_test").to_camel_case().o "someDataTest"
To ignore space, we can set the ignore_space to True >>> Chepy(“some Data_test”).to_camel_case(ignore_space=True).o “some DataTest”
- to_charcode(join_by: str = ' ', base: int = 16) DataFormatT ¶
Convert a string to a list of unicode charcode
Converts text to its unicode character code equivalent. e.g. Γειά σου becomes 0393 03b5 03b9 03ac 20 03c3 03bf 03c5
- Parameters
join_by (str, optional) – String to join the charcodes by. Defaults to ‘ ‘.
base (int, optional) – Base to use for the charcodes. Defaults to 16.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("aㅎ").to_charcode() "61 314e"
- to_decimal(join_by: str = ' ') DataFormatT ¶
Convert characters to decimal
- Parameters
join_by (str, optional) – Join the decimal values by this. Defaults to ‘ ‘.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("aㅎ").to_decimal().o '97 12622'
- to_hex(delimiter: str = '') DataFormatT ¶
Converts a string to its hex representation
- Parameters
delimiter (str, optional) – Delimiter. Defaults to None.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("AAA").to_hex().out.decode() "414141"
- to_html_entity(format='named', all_chars=False) DataFormatT ¶
Encode html entities
Encode special html characters like & > < etc
- Parameters
format (str) – Encoding format. Valid formats are named, numeric and hex. Defaults to named
all_chars (bool) – If all chars should be encoded. By default a-ZA-Z0-9 are skipped. Defaults to False
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy('https://google.com&a="lol"').to_html_entity().o "https://google.com&a="lol""
- to_int(byteorder: Literal['little', 'big'] = 'big', base: int = 10) DataFormatT ¶
Converts the string representation of a number into an int
- Parameters
byteorder (Literal['little', 'big']) – Byte order if state is bytes
base (int) – If state is a str, the base to convert it to.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("1").to_int().o 1
- to_kebab_case() CodeTidyT ¶
Convert string to kebab case
Converts the input string to kebab case. Kebab case is all lower case with dashes as word boundaries. e.g. this-is-kebab-case.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("Some data_test").to_kebab_case().o "some-data-test"
- to_leetcode(replace_space: str = '') DataFormatT ¶
Convert to leetcode. Reference Reference github.com/ss8651twtw/CTF-flag-generator
- Parameters
replace_space (str, optional) – Replace spaces with specified char. Defaults to ‘’.
- Returns
The Chepy object.
- Return type
- to_leetspeak(special_chars: bool = True) CodeTidyT ¶
Convert string to l33t speak
- Parameters
special_chars (bool, optional) – Use special chars in conversion. Defaults to True.
- Returns
The Chepy object
- Return type
Examples
>>> Chepy("somexValue").to_leetspeak().o "50m3%V@1u3"
- to_letter_number_code(join_by: Union[str, bytes] = b' ') EncryptionEncodingT ¶
Encode to A1Z26
- Parameters
join_by (Union[str, bytes], optional) – join output by. Defaults to b’ ‘.
- Returns
The Chepy object.
- Return type
- to_lower_case() CodeTidyT ¶
Convert string to lowercase
Converts every character in the input to lower case.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("HelLo WorLd").to_lower_case().o "hello world"
- to_morse_code(dot: str = '.', dash: str = '-', letter_delim: str = ' ', word_delim: str = '\n') EncryptionEncodingT ¶
Encode string to morse code
- Parameters
dot (str, optional) – The char for dot. Defaults to “.”.
dash (str, optional) – The char for dash. Defaults to “-“.
letter_delim (str, optional) – Letter delimiter. Defaults to ” “.
word_delim (str, optional) – Word delimiter. Defaults to “n”.
- Returns
The Chepy object.
- Return type
- to_nato(join_by: str = ' ') DataFormatT ¶
Convert string to NATO phonetic format.
Example: abc = Alpha Bravo Charlie
- Parameters
join_by (str, optional) – [description]. Defaults to ” “.
- Returns
The Chepy object
- Return type
- to_octal(join_by: str = ' ') DataFormatT ¶
Convert string characters to octal
- Parameters
join_by (str, optional) – Join by. Defaults to “”.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("abㅎ").to_octal().o "141 142 30516"
- to_punycode() DataFormatT ¶
Encode to punycode
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("münchen").to_punycode().o b"mnchen-3ya"
- to_snake_case() CodeTidyT ¶
Convert string to snake case
Converts the input string to snake case. Snake case is all lower case with underscores as word boundaries. e.g. this_is_snake_case.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("helloWorld").to_snake_case().o "hello_world"
- to_unix_timestamp() DateTimeT ¶
Convert datetime string to unix ts
The format for the string is %a %b %d %H:%M:%S %Y, which is equivalent to %c from datatime.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("Sun Nov 10 17:57:29 2019").to_unix_timestamp() "1573426649"
- to_upper_case(by: str = 'all') CodeTidyT ¶
Convert string to uppercase
- Parameters
by (str, optional) – Convert all, by word or by sentence. Defaults to ‘all’.
- Returns
The Chepy object.
- Return type
Examples
Uppercase by word
>>> Chepy("some String").to_upper_case(by="word").o "Some String"
Uppercase by sentence
>>> Chepy("some String").to_upper_case(by="sentence").o "Some string"
Uppercase all
>>> Chepy("some String").to_upper_case(by="all").o "SOME STRING"
- to_upside_down(reverse: bool = False)¶
To upside down
- Parameters
reverse (bool, optional) – Reverse order. Defaults to False.
- Returns
The Chepy object.
- Return type
- to_url_encoding(safe: str = '', all_chars: bool = False) DataFormatT ¶
URL encode
Encodes problematic characters into percent-encoding, a format supported by URIs/URLs.
- Parameters
safe (str, optional) – String of characters that will not be encoded, by default “”
all_chars (bool, optional) – Encode all characters including safe characters
- Returns
The Chepy object.
- Return type
Examples
Url encode while specifying save characters
>>> Chepy("https://google.com/?lol=some data&a=1").to_url_encoding(safe="/:").o "https://google.com/%3Flol%3Dsome+data%26a%3D1"
- to_uuencode(header: str = '-') DataFormatT ¶
To UUEncode
- Parameters
header (str) – header
- Returns
The Chepy object.
- Return type
- triple_des_decrypt(key: str, iv: str = '0000000000000000', mode: str = 'CBC', key_format: str = 'hex', iv_format: str = 'hex') EncryptionEncodingT ¶
Decrypt raw state encrypted with DES.
- Parameters
key (str) – Required. The secret key
iv (str, optional) – IV for certain modes only. Defaults to ‘0000000000000000’.
mode (str, optional) – Encryption mode. Defaults to ‘CBC’.
key_format (str, optional) – Format of key. Defaults to ‘hex’.
iv_format (str, optional) – Format of IV. Defaults to ‘hex’.
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("f8b27a0d8c837edce87dd13a1ab41f96") >>> c.hex_to_str() >>> c.triple_des_decrypt("super secret password !!") >>> c.o b"some data"
- triple_des_encrypt(key: str, iv: str = '0000000000000000', mode: str = 'CBC', key_format: str = 'hex', iv_format: str = 'hex') EncryptionEncodingT ¶
Encrypt raw state with Triple DES
- Parameters
key (str) – Required. The secret key
iv (str, optional) – IV for certain modes only. Defaults to ‘0000000000000000’.
mode (str, optional) – Encryption mode. Defaults to ‘CBC’.
key_format (str, optional) – Format of key. Defaults to ‘hex’.
iv_format (str, optional) – Format of IV. Defaults to ‘hex’.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("some data").triple_des_encrypt("super secret password !!", mode="ECB").o b"f8b27a0d8c837edc8fb00ea85f502fb4"
- unescape_string() UtilsT ¶
Unescape from a string
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("\$ome' d@ta").unescape_string().o "$ome' d@ta"
- unicode_escape(padding: int = 0, uppercase_hex: bool = False) DataFormatT ¶
Unicode escape
- Parameters
padding (int, optional) – Optional padding. Defaults to 0.
uppercase_hex (bool, optional) – Uppercase hex chars. Defaults to False.
- Returns
The Chepy object.
- Return type
- unicode_to_str(as_bytes=False) LanguageT ¶
Escape any u characters to its proper unicode representation
- Parameters
as_bytes (bool) – Treat state as bytes. This does not handle %u or U+ encodings
- Returns
The Chepy object.
- Return type
- unique() UtilsT ¶
Get an array of unique list items
- Raises
StateNotList – If state is not a list
- Returns
The Chepy object.
- Return type
- unzip_all(password: str = None) CompressionT ¶
Unzip all files from zipfile into the state
- Parameters
password (str, optional) – Password if zip is encrypted. Defaults to None.
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("/path/to/zip.zip").load_file() >>> c.unzip_all() [b"Hello World!", b"haha"]
- unzip_one(file: str, password: str = None) CompressionT ¶
Unzip one file from zipfile
Use zip_list_files to get all the filenames within the zip archive
- Parameters
file (str) – Required. Path of file inside the archive
password (str, optional) – Password if zip is encrypted. Defaults to None.
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("/path/to/zip.zip").load_file() >>> c.zip_info() ['somefile.txt', 'some_dir/some_file'...] >>> c.unzip_one("somefile.txt") b"Hello World!"
- vigenere_decode(key: str) EncryptionEncodingT ¶
Vigenere decode
- Parameters
key (str) – Key
- Raises
ValueError – Key is not alpha
ValueError – Key is not provided
- Returns
The Chepy object.
- Return type
- vigenere_encode(key: str) EncryptionEncodingT ¶
Vigenere encode
- Parameters
key (str) – Key
- Raises
ValueError – Key is not alpha
ValueError – Key is not provided
- Returns
The Chepy object.
- Return type
- web(magic: bool = False, cyberchef_url: str = 'https://gchq.github.io/CyberChef/') None ¶
Opens the current string in CyberChef on the browser as hex
- Parameters
magic (bool, optional) – Start with the magic method in CyberChef
cyberchef_url (string, optional) – Base url for Cyberchef
- Returns
Opens the current data in CyberChef
- Return type
None
- without(*values: Any)¶
Remove specified values from the state. Works on strings, bytes, lists and dicts
- Raises
TypeError – If state does not contain valid data
- Returns
The chepy object.
- Return type
- write_binary(path: str) None ¶
Save the state to disk. Return None.
- Parameters
path (str) – The file path to save in.
- Returns
Returns None
- Return type
None
Examples
>>> c = Chepy("some data").write_binary('/some/path/file')
- write_to_file(path: str) None ¶
Save the state to disk. Return None.
- Parameters
path (str) – The file path to save in.
- Returns
Returns None
- Return type
None
Examples
>>> c = Chepy("some data").write_to_file('/some/path/file', as_binary=True)
- xor(key: str, key_type: Literal['hex', 'utf8', 'base64', 'decimal'] = 'hex') EncryptionEncodingT ¶
XOR state with a key
- Parameters
key (str) – Required. The key to xor by
key_type (str, optional) – The key type. Valid values are hex, utf8, decimal and base64. Defaults to “hex”.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("secret").xor(key="secret", key_type="utf8").to_hex() 000000000000
- xor_bruteforce(length: int = 100, crib: Optional[Union[bytes, str]] = None) EncryptionEncodingT ¶
Brute force single byte xor
For multibyte xor bruteforce, use chepy.extras.crypto_extras.xor_bruteforce_multi function
- Parameters
length (int, optional) – How to bytes to bruteforce. Defaults to 100.
crib (Union[bytes, str, None], optional) – Check for crib in xored value. Defaults to None.
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("pf`qfw").xor_bruteforce() {'00': bytearray(b'pf`qfw'), '01': bytearray(b'qgapgv'), '02': bytearray(b'rdbsdu'), '03': bytearray(b'secret'), # here is our secret xored with the hex key 03 '04': bytearray(b'tbdubs'), '05': bytearray(b'ucetcr'), ...} >>> c.get_by_key("03").bytearray_to_str() secret >>> c.xor("03").bytearray_to_str() pf`qfw
- xpath_selector(query: str, namespaces: str = None)¶
Extract data using valid xpath selectors
- Parameters
query (str) – Required. Xpath query
namespaces (str, optional) – Namespace. Applies for XML data. Defaults to None.
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("http://example.com") >>> c.http_request() >>> c.xpath_selector("//title/text()") >>> c.get_by_index(0) >>> c.o "Example Domain"
- yaml_to_json() DataFormatT ¶
Convert yaml to a json string
- Returns
The Chepy object.
- Return type
- zip_compress(file_name: str) CompressionT ¶
Compress the state as a zipfile
- Parameters
filename (str) – File name
- Returns
The Chepy object.
- Return type
- zip_compress_symlink(file_name: str, target_file: str) CompressionT ¶
Create a zipfile with a symlink pointer. For unix
- Parameters
filename (str) – File name
target_file (str) – Target system file
- Returns
The Chepy object.
- Return type
- zip_info() CompressionT ¶
Gets various information about a zip file
This includes information about all the files inside the archive.
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("/path/to/example.zip") >>> c.load_file().zip_info() [{'CRC': 1779821815, '_compresslevel': None, '_raw_time': 19712,...}]
- zip_list_files() CompressionT ¶
Get a list of files inside the zip archive
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("some.zip").load_file().zip_list_files().o ['somefile', 'some_dir/some_file'...]
- zlib_compress(level: int = 9) CompressionT ¶
Compress using zlib
- Parameters
level (int, optional) – Level of compression. 0-9. Defaults to 9.
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("some text").zlib_compress().to_hex().o b"78da2bcecf4d552849ad28010011e8039a"
- zlib_decompress() CompressionT ¶
Zlib decompression
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy("789c0580a10d000008c35ee1b9ca05c104e737b761ca5711e8039a") >>> c.hex_to_bytes() >>> c.zlib_decompress() >>> c.out b"some text"
- bake¶
Alias for out
- cyberchef¶
Alias for web
- log_format¶
Log format message
- log_level¶
Log level
- property o¶
Get the final output
- Returns
Final output
- Return type
Any
- property out: Any¶
Get the final output
- Returns
Final output
- Return type
Any
- read_file¶
Alias for load_file
- property recipe: List[Dict[str, Union[str, Dict[str, Any]]]]¶
Returns the current recipe. This is a list of dictionaries that contains the method name and the arguments.
- Returns
The recipe.
- Return type
List[Dict[str, Union[str, Dict[str, Any]]]]
- write¶
Alias for write_to_file
- chepy.search_chepy_methods(search: str) None ¶
Search for Chepy methods
- Parameters
search (str) – String to search for