A cryptographic program implementing an enhanced Caesar cipher algorithm with a dynamic key and non-linear transformations. The project combines classical approaches with modern mathematical methods to create robust encryption.
- Flexible shuffled alphabet based on the user's key
- Dynamic shift using trigonometric functions
- Multiple transformation layers for increased cryptographic strength
- Extended character support: Latin, Cyrillic, special characters
def PiecewiseShuffledAlphabet(key: str, alph: str) -> list[str]:- Computes divisors of the alphabet length for optimal partitioning
- Removes duplicates and spaces from the key
- Converts the key into a numeric sequence
- Splits the alphabet into blocks and shuffles each block by the key
- Merges blocks with additional permutation
coef: float = abs(len(key) * sin(len(word) * len(key))) + len(key)
shift: int = abs(round(
(coef ** 2)
* (cos(len(word) / len(key) - 1) / sin(len(key) / len(word) + 1))
* (sin(len(word) / len(key) + 1) / cos(len(key) / len(word) - 1))
))Uses a non-linear combination of trigonometric functions of the key and text parameters, making the shift unpredictable.
- Text reversal under certain length conditions
- Cyclic shift of alphabet blocks
- Modular arithmetic for alphabet operations
- Language: Python 3.12
- Encryption type: Symmetric block encryption
- Math foundation: Trigonometric functions, modular arithmetic, number theory
- Supported characters: 150 symbols (Latin, Cyrillic, punctuation, special characters)
- Input key is cleaned from duplicates and spaces
- Optimal block sizes are calculated based on alphabet length divisors
- Alphabet is split into blocks and shuffled by the key
- Blocks are reordered to form the final alphabet
- A complexity coefficient is computed from key and text lengths
- A dynamic shift is calculated using trigonometric functions
- Additional text reversal is applied under specific conditions
- Each character is transformed through the shuffled alphabet
- Dynamic shift is applied with modular arithmetic
- Characters outside the alphabet are preserved unchanged
- Python 3.12+
- Standard Python libraries:
math,enum,sys
git clone https://github.com/your-username/cesar_len_key.git
cd cesar_len_key
uv synccesar-len-keycesar-len-key-file input.txt -k mykey # encrypt
cesar-len-key-file input.txt -k mykey -d # decrypt
cesar-len-key-file input.txt -k mykey -o output.txt # specify outputAdd the package as a git dependency via uv:
# In your other project:
uv add git+https://github.com/UmbrellaLeaf5/cesar_len_keyThen import and use the public API:
from cesar_len_key import CryptedLines, CryptedWords, CryptType, DEFAULT_ALPHABET
# Encrypt a flat list of words
words = ["password1", "secret_token"]
encrypted = CryptedWords(words, "master_key")
decrypted = CryptedWords(encrypted, "master_key", crypt_type=CryptType.decr)
assert decrypted == words
# Encrypt text line-by-line, preserving structure
lines = ["service: my_login", "password: my_password", ""]
encrypted_lines = CryptedLines(lines, "master_key")
decrypted_lines = CryptedLines(encrypted_lines, "master_key", crypt_type=CryptType.decr)
assert decrypted_lines == lines
# Use a custom alphabet (optional)
custom_alph = "abc123!@#"
result = CryptedWords(["hello"], "key", alphabet=custom_alph)| Name | Type | Description |
|---|---|---|
CryptedLines |
function | Encrypt/decrypt a list of strings line-by-line |
CryptedWords |
function | Encrypt/decrypt a flat list of words |
CryptType |
Enum | CryptType.encr / CryptType.decr |
CryptedWord |
function | Low-level single-word encryption |
DEFAULT_ALPHABET |
constant | The 150-character default alphabet |
WELCOME to the CesarLenKey! This is a program, where you can crypt your text!
You can use Cyrillic or Latin alphabet and some specials chars.
(just try it, there is interesting algo :)
Enter text to crypt (1 string):
Hello, how is it going?
Encryption (Enter 1) or Decryption (Enter 0)?
1
Enter cryption key (some string):
difiowefmjlkw2819
Result (with key difiowefmjlkw2819):
bJ)wt0 yt! 3X jc 3tVwL$
Press any key to continue using program...
(use Ctrl + Z to exit)
WELCOME to the CesarLenKey! This is a program, where you can crypt your text!
You can use Cyrillic or Latin alphabet and some specials chars.
(just try it, there is interesting algo :)
Enter text to crypt (1 string):
bJ)wt0 yt! 3X jc 3tVwL$
Encryption (Enter 1) or Decryption (Enter 0)?
0
Enter cryption key (some string):
difiowefmjlkw2819
Result (with key difiowefmjlkw2819):
Hello, how is it going?
Press any key to continue using program...
(use Ctrl + Z to exit)
DivisorsList()— divisor computation for split optimizationRemadeKey()— key to numeric sequence conversionPiecewiseShuffledAlphabet()— block-based alphabet shufflingShuffledAlphabet()— final shuffled alphabet assemblyCryptedWord()— core single-word encryptionCryptedWords()— public: encrypt/decrypt a word listCryptedLines()— public: encrypt/decrypt text line-by-line
Important: This algorithm is intended for educational and personal use. For protecting critically important information, use industry-standard encryption (AES, RSA, etc.).