Nodes/ComfyUI ARG Toolkit/Two Square (Double Playfair) Cipher
ComfyUI Node

Two Square (Double Playfair) Cipher

The Digraph-friendly Double Playfair

By AzelusLightvale·Created 12 months ago·Updated 4 days ago· 1
Two Square (Double Playfair) Cipher
    • encrypted_txt
    textHello World!
    alphabetENGLISH
    modetrue
    keep_formattingtrue
    key_1
    key_2

    The Two-Square cipher (a.k.a. Double Playfair) is the "more secure Playfair" that Félix Delastelle built in the 1890s, and it fixes the original's biggest flaw: Playfair encrypts two letters at a time but does it so uniformly that an attacker can spot the patterns. Two-Square uses two keyed 5×5 squares instead of one, so the digraph transformation changes depending on where each letter sits in its own square. Cracking it requires knowing both keys, and it shrugs off simple frequency analysis far better than its single-square ancestor.

    For an ARG, it hits a nice difficulty sweet spot: it looks like a serious block cipher to players, it's learnable, and the "two keys" structure makes for a natural two-stage puzzle - find key A here, key B there.

    How it works

    Built on secretpy. Inputs:

    • text - the message.
    • key_1 and key_2 - keyword strings (any text in the alphabet's language) used to build the two 5×5 squares. Each square is filled with the keyword first, then the rest of the alphabet, deduplicating letters. Two keys, two squares, twice the work for the solver.
    • mode - encrypt/decrypt toggle.
    • keep_formatting - on preserves formatting; off strips to lowercase letters.
    • alphabet - default ENGLISH.

    Output: encrypted_txt (STRING).

    The mechanics: each plaintext digraph is located in the two squares, and each letter is replaced by the letter at the same position in the other square - but which square you look in depends on the letter's row, which is where the two-key complexity comes from. Odd digraphs get an x filler inserted, a Playfair family trait.

    The inputs that matter

    text, key_1, and key_2 are the game. Both keys are secrets, and both must be non-empty for the squares to build properly. The mode toggle flips between encrypt and decrypt - same keys, both directions.

    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

    • Empty key - an empty key_1 or key_2 produces a degenerate square and garbage. Type real keywords.
    • Odd-length or doubled-letter plaintext - the Playfair family inserts filler x characters to make digraphs; if your decrypt output has stray xs, that's the cipher being a cipher, not the node being wrong.
    • Wrong key order - the two keys are not interchangeable in general; swap them and the squares change. If decryption fails, try key_1/key_2 swapped before assuming breakage.
    CategoryARG Toolkit/Cryptography/Classical

    Inputs (6)

    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.
    key_1STRINGAccepts any text (or alphabet) in the alphabet's language as the first key to decrypt/encrypt.
    key_2STRINGAccepts any text (or alphabet) in the alphabet's language as the first key to decrypt/encrypt.

    Outputs (1)

    NameTypeDescription
    encrypted_txtSTRING