| .gitignore | ||
| main.py | ||
| README.md | ||
Multi-Cipher Text Encoder
This Python script allows you to encode and decode text using a variety of ciphers. You can apply multiple ciphers sequentially to a given text. The script also generates a template describing the applied ciphers and the final encoded text, which can be useful for puzzles or web novel content.
Features
- Supports multiple cipher types.
- Allows chaining of ciphers.
- Prompts for parameters for ciphers that require them (e.g., Vigenère key, Caesar shift).
- Generates a formatted output template with cipher descriptions and the encoded text.
- Flexible command-line interface for specifying text, ciphers, and number of operations.
Requirements
- Python 3.x
How to Run
The script is run from the command line using python3 main.py.
Command-Line Arguments
-t TEXT, --text TEXT:- The input text string you want to encode.
- If not provided, defaults to:
"Hello, World! 123 This is a test."
-c CIPHER1 [CIPHER2 ...], --ciphers CIPHER1 [CIPHER2 ...]:- A space-separated list of cipher keys to apply in the specified order.
- Rule: All word-based ciphers must appear before any letter-based ciphers in the sequence.
- This argument is mutually exclusive with
--random. You must use either--ciphersor--random.
-r, --random:- Randomly selects ciphers to apply.
- If
--num-ciphersis not specified, defaults to selecting 3 ciphers. - The random selection will pick at most one word-based cipher and place it first if chosen.
- This argument is mutually exclusive with
--ciphers.
-n NUM_CIPHERS, --num-ciphers NUM_CIPHERS:- An integer specifying the number of ciphers to apply.
- With
--random: Determines how many random ciphers are selected. - With
--ciphers: Acts as a limiter. If you provide more ciphers in the-clist thanNUM_CIPHERS, only the firstNUM_CIPHERSfrom your list will be used. IfNUM_CIPHERSis greater than the number of ciphers you listed, all listed ciphers will be used. - If not provided when using
--ciphers, all specified ciphers are used. - If not provided when using
--random, it defaults to 3.
-h, --help:- Shows the help message detailing all arguments and available ciphers.
Available Ciphers
You can get an up-to-date list of available cipher keys by running python3 main.py --help. The script will list all choices for the --ciphers argument.
Currently, the available ciphers are:
-
Word-Based Ciphers (Manipulate the order or content of whole words):
reverse_word_order: Splits the string by white space, then joins the tokens in reverse order.word_replacement: Replaces words with peaceful alternatives based on word length (prompts for dictionary if not using defaults).
-
Letter-Based Ciphers (Manipulate individual characters or blocks of characters):
caesar: Shifts letters by a specified number of positions (prompts for shift value, e.g., 3, -5).atbash: A simple substitution cipher where letters are mapped to their reverse in the alphabet (A->Z, B->Y, etc.).vigenere: Encrypts using a keyword (prompts for the key).block_reverse: Pads text with '#' to make its length a multiple of 3, splits into 3-char blocks, reverses each block, and concatenates.reverse_capitalize: Reverses the entire string and capitalizes the first letter.grid_coordinate: Maps letters to (row,col) coordinates in a user-defined grid (prompts for grid dimensionsaandb).reverse_chars_in_words: Splits by white space, then reverses the characters within each token.hex_encode: Converts every character to its two-digit hexadecimal representation (e.g., 'A B' becomes '412042').
(Note: The ascii_replace cipher is commented out in the source code but can be re-enabled if needed.)
Cipher Parameters
Some ciphers require additional parameters. If you select such a cipher, the script will prompt you to enter the necessary information:
- Caesar Cipher (
caesar): Prompts for the shift value (integer between -25 and 25).- Example prompt:
Enter the Caesar cipher shift value (integer between -25 and 25). Press Enter for default (15):
- Example prompt:
- Vigenère Cipher (
vigenere): Prompts for the Vigenère key.- Example prompt:
Enter the Vigenère cipher key (or press Enter to use default: 'BUTTERFLY'):
- Example prompt:
- Grid Coordinate Cipher (
grid_coordinate): Prompts for grid dimensionsa(rows) andb(columns).- Example prompt:
Enter grid dimensions 'a' and 'b' (e.g., '5 6'). Press Enter for default (5 6):
- Example prompt:
- Word Replacement Cipher (
word_replacement): This cipher uses a predefined list of peaceful words. No user input is required for parameters during runtime unless customized to do so.
Examples
-
Apply a specific sequence of ciphers:
python3 main.py -t "My secret message" -c word_replacement vigenere caesarThis will:
- Apply
word_replacement. - Then apply
vigenere(will prompt for key). - Then apply
caesar(will prompt for shift).
- Apply
-
Apply random ciphers (default 3):
python3 main.py --text "Encode this randomly" --random -
Apply 5 random ciphers:
python3 main.py -t "Another random test" -r -n 5 -
Specify ciphers but limit to 2:
python3 main.py -t "Limit these" -c hex_encode atbash caesar -n 2This will only apply
hex_encodeand thenatbash. -
Using a word-based cipher followed by letter-based ciphers:
python3 main.py -t "Word first" -c reverse_word_order caesar atbash -
Using multiple word-based ciphers, then letter-based:
python3 main.py -t "Many words then letters" -c reverse_word_order word_replacement vigenere
Output
The script will output:
- The selected ciphers and their types (Word-based/Letter-based).
- The original text.
- Step-by-step application of each cipher, showing its description and the result after application.
- The final encoded text.
- A "Cipher Template Output" formatted for use in a web novel or similar context. This template includes:
- The final encoded text.
- Step-by-step instructions (in decoding order) on how to restore the original plan, using the descriptions of the applied ciphers.
Understanding the Output Template
The CIPHER_TEMPLATE section in the output is designed to be a set of instructions for decoding the message. The steps are listed in the reverse order of how they were applied during encoding.
Example: If you encoded with CipherA -> CipherB -> CipherC.
The template instructions will be:
- Instruction to decode
CipherC. - Instruction to decode
CipherB. - Instruction to decode
CipherA.
This helps a reader (or a character in a story) understand how to decrypt the message.