Playfair Cipher
The digraph cipher that hid British secrets in WWI
- encrypted_txt
Playfair is the World War I classic that encrypts letters two at a time instead of one, which made it a genuine improvement over single-letter substitution back in 1914 - and makes it a recurring favorite in ARGs and puzzle hunts today, because the output resists the letter-frequency analysis that kills simple ciphers. The Playfair node gives you it in the graph, encrypt and decrypt both.
Here's the mechanism. You build a 5×5 square of the alphabet, seeded by a keyword (I/J get merged - standard Playfair behavior). Then you split your message into letter pairs, inserting a filler letter like X between doubled pairs, and for each pair you do one of three things depending on where the letters sit in the square: same row → shift each letter right; same column → shift each down; otherwise → swap to the corners of the rectangle they define. Decryption is the same rules run backwards. It's fiddly by hand and instant in a node.
Inputs match the pack's classical-cipher template:
- text - the message, plain string, multiline.
- key - the keyword that seeds the 5×5 square. The tooltip in the pack describes it as an alphabet of equivalent length to the chosen alphabet, but in practice
secretpytreats it as the keyword it uses to scramble the square - type any word in your alphabet's language and the square gets built from it. Same keyword on encrypt and decrypt, exactly, or you get noise. - alphabet - defaults to
ENGLISH. Playfair wants a square whose side is the square root of your alphabet's length (25 for English), so if you use a custom alphabet keep the length a perfect square. - mode - encrypt or decrypt.
- keep_formatting - on by default: letters get encrypted, case and punctuation restored. Off: clean lowercase ciphertext, which is the form you'd actually hand to a solver.
Output is encrypted_txt, a STRING - long enough that the message length roughly doubles in ciphertext, because every doubled letter pair gains a filler X. That's expected Playfair behavior, not a bug.
Install: ComfyUI Manager → search "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; the classical ciphers all run on the pack's secretpy dependency, which Manager installs.
One thing to watch: because Playfair merges I and J, the ciphertext won't distinguish them, and decrypting "IJAM" versus "JAM" comes out the same - that's a feature of the cipher, not a limitation of this node. And keep the author's caveat in mind: amateur project, tests cover the common cases. Feed it normal sentences and it behaves; throw gnarly punctuation or a mismatched key at it and expect garbage rather than an error.
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 | STRING | Accepts an alphabet of equivalent length to the chosen alphabet as the key to decrypt/encrypt. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| encrypted_txt | STRING | — |