Zigzag (Rail-fence) Cipher
Dumb in the best way, and it actually works
- encrypted_txt
The rail-fence (zigzag) cipher is the cipher that's so transparent even a kid can crack it - which is exactly why it's great for an ARG's opening riddle and useless for anything that actually needs secrecy. This node, part of the ComfyUI ARG Toolkit, does exactly one thing and does it without drama. I ran a full round trip on the shipped code: Hello World! with 4 rails comes back as Hoewr Lolld!, and decrypt restores the original. No surprises, no broken internals, which puts it ahead of some of its siblings in this pack.
Here's the mechanism, and it's a visual one: you write the plaintext down a series of diagonal "rails" like a zigzag across an imaginary fence, then read it off row by row. The ciphertext is just those rows concatenated. No substitution, no letter swapping - pure transposition, meaning the same letters appear in the output, just rearranged. That's why it's trivially crackable by anagram analysis, and why it's a perfect "decoy" layer to stack under something real.
The inputs are simple:
- text - the message, multiline. Default "Hello World!".
- key - the number of rails, an integer with a default of 13 and a minimum of 1. This is the one you actually set. More rails = more scatter; 2 is a barely-there scramble, 13 is a proper jumble. The tooltip says "any non-negative integer" but the schema enforces a floor of 1, which is fine because 0 rails would be nonsense anyway.
- mode -
trueencrypts,falsedecrypts. - keep_formatting -
truepreserves spaces, punctuation, and case;falsestrips it all and lowercases. Keep both sides of a round trip on the same setting. - alphabet - technically present in the schema, but the code ignores it entirely. It's a leftover from the shared base class the classical ciphers use; for a transposition cipher there's nothing to alphabetize. You can leave it at
ENGLISHand never think about it again.
Output is one encrypted_txt string. The 13-rail default is a fun Easter egg - 13 rails on a 12-char default message is a near-total shuffle - but honestly you'll want 2–4 rails for a solvable ARG puzzle.
Install is the pack standard: ComfyUI Manager → search "ComfyUI ARG Toolkit" → install → restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/AzelusLightvale/ComfyUI-ARG-Toolkit
# restart ComfyUI
The pack itself is one-author (AzelusLightvale), GPLv3, and the README is upfront that it started as an amateur project with tests covering only common cases. The dependency list is bigger than this node deserves - the pack pulls secretpy, cryptography, stegano, invisible-watermark, and reedsolo, and the watermark library hauls torch and opencv in with it, so your first ComfyUI start after installing gets noticeably slower. The cipher engine for this node is secretpy, which is a small pure-Python library, so at least the actual code path here is light.
Common issues are few. The one that trips people up: if keep_formatting is off, your spaces and punctuation get stripped before encrypting, so the ciphertext comes back as one lowercase blob - that's expected, and the decrypt side needs the same setting to restore it. And because this is a pure transposition, the output length always matches the input length, which is a nice sanity check when you're debugging a workflow: if the ciphertext length doesn't match, you grabbed the wrong node's output.
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 | INT | 13 | Accepts any non-negative integer as the key to decrypt/encrypt. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| encrypted_txt | STRING | — |