Nodes/ComfyUI ARG Toolkit/Zigzag (Rail-fence) Cipher
ComfyUI Node

Zigzag (Rail-fence) Cipher

Dumb in the best way, and it actually works

By AzelusLightvale·Created 12 months ago·Updated 5 days ago· 1
Zigzag (Rail-fence) Cipher
    • encrypted_txt
    textHello World!
    alphabetENGLISH
    modetrue
    keep_formattingtrue
    key13

    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 - true encrypts, false decrypts.
    • keep_formatting - true preserves spaces, punctuation, and case; false strips 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 ENGLISH and 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.

    CategoryARG Toolkit/Cryptography/Classical

    Inputs (5)

    NameTypeDefaultDescription
    textSTRINGHello World!
    alphabetSTRINGENGLISHInput 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.
    modeBOOLEANtrueToggle between encrypting or decrypting a message.
    keep_formattingBOOLEANtrueToggle between preserving the format of the message or remove all spaces, punctuations, and convert to lowercase.
    keyINT13Accepts any non-negative integer as the key to decrypt/encrypt.

    Outputs (1)

    NameTypeDescription
    encrypted_txtSTRING