Nodes/ComfyUI ARG Toolkit/Bitwise XOR Operator
ComfyUI Node

Bitwise XOR Operator

The reversible operator that shows up everywhere in ARGs

By AzelusLightvale·Created 12 months ago·Updated 5 days ago· 1
Bitwise XOR Operator
    • bitwise_txt
    text_1Hello World!
    text_2Hello World!
    datatypeBinary
    encoding_format
    other_encoding_format

    If you only ever use one node from the ARG Toolkit's bitwise family, make it this one. Bitwise XOR takes two strings and flips each bit where the inputs differ - 1 XOR 1 = 0, 1 XOR 0 = 1. That single property, reversibility, makes it the workhorse of light cryptography and puzzle design: XOR the message with a key and you get ciphertext; XOR the ciphertext with the same key and the message comes right back. It's how one-time-pad schemes work, it's how a huge chunk of historical ciphers get bolted together, and it's the answer to roughly half the "why does this look like random noise" questions in ARG solving.

    The classic trick is the self-check: A XOR A = 0 and A XOR B XOR B = A. If a puzzle hands you two strings and says "combine them," and you're not sure whether it means XOR - try it. There's no guessing about whether you did it right, because running the same two inputs through again inverts the operation. That's more than OR and AND can claim, and it's why XOR is the operator you'd actually wire into a real workflow rather than just tinker with.

    How it works

    The node decodes both text_1 and text_2 into raw bytes using the datatype you choose, applies x ^ y byte-by-byte, and re-encodes the result into that same format. Two operational rules you'll hit quickly:

    1. Lengths must match. text_1 and text_2 have to decode to the same number of bytes or the node throws ValueError: Inputs must be same length for bitwise operations. For a key XOR that's natural - you XOR against a key of equal length - but "Hello" vs "World!" will refuse, so pad or trim.
    2. It works on bytes, not text. Pick Hexadecimal or Binary datatype for raw data. If you insist on String, the node XORs UTF-8 bytes and tries to decode the result - valid XOR output isn't guaranteed valid UTF-8, and you'll get a UnicodeDecodeError when it isn't.

    The inputs that matter

    • text_1 - the message (or the "main string to compare against," per the tooltip).
    • text_2 - the key / second operand. Same length requirement, same datatype.
    • datatype - interpretation of both inputs and the output: String, Hexadecimal, Base64, Integer, Binary.
    • encoding_format - only relevant for String datatype; Other + other_encoding_format for custom codecs.

    Output is a single bitwise_txt string in the input's format.

    Installing it

    Ships in the ComfyUI ARG Toolkit pack. Install via ComfyUI Manager (search "ComfyUI ARG Toolkit") or:

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

    Restart ComfyUI. Dependency install is the slow part - the pack pulls cryptography, secretpy, stegano, invisible-watermark, reedsolo, and transitively torch plus opencv-python. No models, no keys, fully local.

    Gotchas

    The equal-length requirement is where people lose minutes. And a genuinely useful ARG habit: if you suspect a string was XOR'd with a repeated key, XOR it against a repeated guess of the key's first byte and look for legible text - this node makes that brute-force loop trivial if you're willing to chain a few of them. Just remember the output format follows the input datatype, and string-datatype XOR output will often refuse to decode.

    CategoryARG Toolkit/Utilities/Bitwise

    Inputs (5)

    NameTypeDefaultDescription
    text_1STRINGHello World!The main string to compare against. Accepts format defined in `datatype`
    text_2STRINGHello World!The secondary string to compare against. Accepts format defined in `datatype`
    datatypeCOMBOBinaryThe datatype that the two texts is assumed to be for comparison purpose. Will also output the final output based on the chosen datatype as well.
    encoding_formatCOMBOThe encoding format available for text, may yield different results when converting.
    other_encoding_formatoptSTRINGIf, for some reason, your chosen encoding format is not available in the dropdown, select "Other" in encoding_format and type in your encoding format here. Supports all format written in Python's `encoding` module.

    Outputs (1)

    NameTypeDescription
    bitwise_txtSTRING