Simple Substitution Cipher
The all-purpose monoalphabetic swap
- encrypted_txt
A simple substitution cipher is the "scramble the alphabet" trick: you map every letter of the alphabet to another letter, one-to-one, and the key is literally the mapping. Caesar is the degenerate case (a shifted alphabet); this node is the full general version, where your key can be any permutation. It's the cipher that shows up in every newspaper's cryptogram puzzle, which makes it a fantastic ARG staple - recognizable, solvable by hand with frequency analysis, and endlessly re-skinnable.
Be honest about the trade-off: it's also the textbook example of a weak cipher. Monoalphabetic substitution preserves letter frequencies, so a determined solver with a printed frequency table (or the knowledge that 'e' is the most common English letter) will crack it in an afternoon. That's not a bug - for a puzzle you want the solver to succeed.
How it works
Built on secretpy. Inputs:
- text - the message.
- key - a string of the same length as your alphabet, mapping each letter to its substitute. For the default English alphabet that's a 26-character string. The classic demo key is
zyxwvutsrqponmlkjihgfedcba(reverse alphabet, aka Atbash as a substitution). - mode - encrypt/decrypt toggle.
- keep_formatting - on preserves spaces/punctuation/case; off strips to lowercase letters.
- alphabet - default
ENGLISH.
Output: encrypted_txt (STRING).
Mechanically, the node takes your alphabet, builds a translation table from the key, and substitutes character-by-character. Decrypting just reverses the table. The only real requirement is that the key is the same length as the alphabet - a 25-character key against a 26-letter alphabet will misbehave.
The inputs that matter
text and key are the whole game. If you're designing a puzzle: make up any 26-letter permutation for the key, encrypt, and hand the solver the ciphertext plus a hint that it's a simple substitution - the key itself is the secret to protect. For solving, the keep_formatting setting matters: ciphertext with spaces intact is dramatically easier to crack by frequency analysis, so many puzzle-makers ship it stripped.
Installing it
Part of ComfyUI ARG Toolkit - ComfyUI Manager (search "ComfyUI ARG Toolkit") or:
cd ComfyUI/custom_nodes
git clone https://github.com/AzelusLightvale/ComfyUI-ARG-Toolkit
Restart ComfyUI. Runs on secretpy; no model files.
Common issues
- Key length mismatch - your key must match the alphabet's length (26 for English). Count the characters.
- Letters you didn't map - non-alphabet characters pass through untouched. If you stripped formatting, make sure the puzzle text only contains alphabet letters, or decrypts get noisy.
- Looks like Atbash? That just means your key happens to be the reversed alphabet. Any permutation works - you're not stuck with the symmetric ones.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | Hello World! | — |
| alphabet | STRING | ENGLISH | Input your alphabet here. If left blank, uses the alphabet default to the cipher. Uses standard connected format ('abcdef'), but can also accept the alphabets defined in secretpy in alphabets.py. |
| mode | BOOLEAN | true | Toggle between encrypting or decrypting a message. |
| keep_formatting | BOOLEAN | true | Toggle between preserving the format of the message or remove all spaces, punctuations, and convert to lowercase. |
| key | STRING | Accepts an alphabet of equivalent length to the chosen alphabet as the key to decrypt/encrypt. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| encrypted_txt | STRING | — |