stringtool¶
Cryptography¶
Author: Jacek Kotlarski –<szumak@virthost.pl> Created: 16.10.2023
Purpose: Provide simple, string-centric cryptographic helpers.
This module offers lightweight encoding and cipher helpers intended for quick experiments and utilities that operate on user-provided keyboard input.
- class jsktoolbox.stringtool.crypto.SimpleCrypto[source]¶
Bases:
NoDynamicAttributesUtility class for lightweight string encryption and encoding routines.
- static chars_table_generator()[source]¶
Build the character table used by Caesar-style transformations.
### Returns: [str] - Ordered set of printable and selected Unicode characters used for mapping.
- Return type:
- classmethod salt_generator(length=8)[source]¶
Generate a numeric salt with the requested number of digits.
### Arguments: * length: int - Desired digit count for the generated salt.
### Returns: [int] - Random salt constrained to the given length.
### Raises: * ValueError: Provided length is less than 1.
- classmethod caesar_encrypt(salt, message)[source]¶
Encode a message using a Caesar cipher over the generated table.
### Arguments: * salt: int - Value used to derive the rotation offset. * message: str - Plain-text message to encode.
### Returns: [str] - Encoded message.
### Raises: * TypeError: Salt is not an integer. * TypeError: Message is not a string instance.
- classmethod caesar_decrypt(salt, message)[source]¶
Decode a Caesar-encrypted message using the generated table.
### Arguments: * salt: int - Value used to derive the rotation offset. * message: str - Encoded message to decode.
### Returns: [str] - Plain-text message.
### Raises: * TypeError: Salt is not an integer. * TypeError: Message is not a string instance.
- classmethod rot13_codec(message)[source]¶
Perform ROT13 translation for ASCII-compatible text.
### Arguments: * message: str - Text to encode or decode using ROT13.
### Returns: [str] - Transformed message.
### Raises: * TypeError: Message is not a string instance.
- classmethod b64_encrypt(message)[source]¶
Encode a string as Base64 using UTF-8 bytes.
### Arguments: * message: str - Text to encode.
### Returns: [str] - Base64-encoded representation.
### Raises: * TypeError: Message is not a string instance.
- classmethod b64_decrypt(message)[source]¶
Decode a Base64 string assuming UTF-8 payload.
### Arguments: * message: str - Base64 text to decode.
### Returns: [str] - Decoded plain-text message.
### Raises: * TypeError: Message is not a string instance. * ValueError: Provided payload is not valid Base64.
- classmethod multiple_encrypt(salt, message)[source]¶
Apply Caesar, ROT13, and Base64 encoders sequentially.
The method first performs ROT13, then a Caesar shift, and finally Base64 encoding to produce a layered transformation.
### Arguments: * salt: int - Value used to derive the Caesar translation offset. * message: str - Plain-text message to encode.
### Returns: [str] - Result of the chained encoders.
### Raises: * TypeError: Message is not a string instance.
- classmethod multiple_decrypt(salt, message)[source]¶
Reverse the layered encoding applied by multiple_encrypt.
### Arguments: * salt: int - Value used to derive the Caesar translation offset. * message: str - Encoded message produced by multiple_encrypt.
### Returns: [str] - Original plain-text message.
### Raises: * TypeError: Message is not a string instance. * ValueError: Nested Base64 payload is invalid.