Nodes/ComfyUI ARG Toolkit/Polybius Square Cipher
ComfyUI Node

Polybius Square Cipher

Reduce every letter to two numbers

By AzelusLightvale·Created 12 months ago·Updated 4 days ago· 1
Polybius Square Cipher
    • encrypted_txt
    textHello World!
    alphabetENGLISH
    modetrue
    keep_formattingtrue
    key

    The Polybius square is one of the oldest ciphers there is - a 5×5 grid where each letter becomes a two-digit coordinate, row then column. A becomes 11, B becomes 12, and so on. It's not secure in any modern sense; it's a transcription of letters into numbers, which is exactly why it's everywhere in ARGs. Puzzle makers love leaving a string of digits that only resolves once you know the grid. The Polybius node does that conversion in the graph.

    Mechanically, the square is filled with the alphabet (I/J merged for English, so 25 letters fit in 5×5), and the node maps each letter to its coordinates and back. The pack's version also lets you seed the square with a key - a string whose length must match the square root of your alphabet's length (so 5 for the 25-letter English alphabet). If you leave the key as a plain alphabet order, you get the textbook square; if you scramble it with a keyword, you get a keyworded variant that matches the twistier puzzle versions.

    Inputs, same template as the other classical ciphers:

    • text - the message, plain string.
    • key - the string whose length matches the square root of your alphabet length.
    • alphabet - ENGLISH by default; if you use a custom alphabet, keep its length a perfect square so the grid works out.
    • mode - encrypt or decrypt.
    • keep_formatting - on by default (letters → coordinates, case/punctuation preserved around them); off gives clean output with no spaces.

    Output is encrypted_txt - a STRING of numbers, with formatting on, that's the point: ciphertext that reads as digits.

    Install: ComfyUI Manager → "ComfyUI ARG Toolkit" → install → restart, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/AzelusLightvale/ComfyUI-ARG-Toolkit
    

    Restart ComfyUI; it's under ARG Toolkit/Cryptography/Classical. No model downloads; secretpy does the heavy lifting.

    Now the honest heads-up, and it's a real one: as shipped in version 2.2.1, the validation in polybius() compares the key string directly to the square-root number - two things that can never be equal - so the node raises a ValueError on every run, no matter what you type. This is a bug in the source, not something you're doing wrong. If you hit it, the one-line patch is in custom_nodes/ComfyUI-ARG-Toolkit/src/ciphers.py: change if key != math.sqrt(len(alphabet)): to if len(key) != int(math.sqrt(len(alphabet))): and restart ComfyUI. Until the author ships a fix, that's the difference between this node working and erroring. The author is upfront that this is an amateur project with light test coverage, and this is precisely the kind of edge case that slips through - worth knowing before you blame your workflow.

    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.
    keySTRINGAccepts an string of length that matches the square root of the length of your alphabet length.

    Outputs (1)

    NameTypeDescription
    encrypted_txtSTRING