ForHosting KIT · Developer Utilities

Four-square cipher encoder and decoder

Encrypt letter pairs with Delastelle's four-square cipher and two keywords: HELPME with the keys EXAMPLE and KEYWORD becomes FYNFNE, and the same keywords turn it back. Spaces and punctuation are dropped, and J counts as I. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Text
HELPME
Key1
EXAMPLE
Key2
KEYWORD
Calculation mode
encrypt
You get
Result
FYNFNE
Encoding
four_square
Key1 letters
EXAMPLE
Key2 letters
KEYWORD

This four-square cipher tool encrypts or decrypts text with the classical digraph substitution invented by Félix Delastelle. Two keywords fill the upper-right and lower-left 5×5 squares while the upper-left and lower-right squares hold a fixed twenty-five letter alphabet where J is mapped to I. Plaintext is processed in letter pairs: the first letter of each digraph is located in the upper-left square and the second in the lower-right square; ciphertext letters are read from the keyed squares at the complementary row and column, so the mapping depends on both keywords at once rather than a single repeating stream. Non-letter characters are stripped before pairing, an odd letter count is padded with X, and the result is returned as continuous uppercase letters together with the four flattened squares for inspection.

What the four-square cipher is and what this tool returns

The four-square cipher is a digraph substitution over a twenty-five letter Latin alphabet arranged as four Polybius squares. The upper-left and lower-right squares use the same plain order with J combined into I so every letter has a unique cell. The upper-right square is filled first with unique letters from the first keyword and then with the remaining alphabet; the lower-left square is filled the same way from the second keyword.

Encryption takes a pair of plaintext letters, finds the first in the upper-left square and the second in the lower-right square, then emits the letter at the first letter row and second letter column in the upper-right square followed by the letter at the second letter row and first letter column in the lower-left square.

Decryption reverses the lookups by reading ciphertext digraphs from the keyed squares and recovering plaintext from the plain squares, so encrypt then decrypt with the same keywords restores the normalized letter stream including any X pad that was added for an odd count. This page always uses that textbook rule with no optional alphabet tables that could drift between locales.

Where four-square fits in lessons and puzzles

Developers and educators meet the four-square cipher in capture-the-flag warm-ups, textbook chapters on classical digraph cryptology, and lightweight demos that show how two independent keyword squares strengthen a simple pair substitution beyond a single Playfair table. Frontend teams can scramble sample phrases for screenshots without inventing a custom alphabet, then recover them with decrypt under the same keys. Backend services encode short challenge strings for puzzle APIs or teaching sandboxes where students must apply both keywords correctly to unlock the next step.

Quality engineers generate deterministic encrypt and decrypt pairs for contract tests so a middleware that claims four-square support cannot silently switch to a monoalphabetic map. Contest organizers precompute answer keys for modest English phrases without trusting opaque web toys that change padding rules or omit the J-to-I convention. Product and education tools use the transform when a learner pastes ciphertext and the UI must show the recovered plaintext under the documented keywords.

Pair it with other classical encoding helpers when you are building a small lab of free, deterministic text tools, and never treat four-square as a substitute for modern authenticated encryption.

CTF and classical digraph practice

Encrypt and decrypt two-keyword digraph phrases for puzzles, classrooms, and capture-the-flag warm-ups.

History-of-crypto lessons

Demonstrate four 5×5 squares, J-to-I alphabets, X padding, and why empty keywords must be rejected.

What does the four-square cipher tool cost?

It is free in your browser on this page.

How do I decrypt a four-square message?

Send the ciphertext as text, the same key1 and key2 used to encrypt, and set mode to decrypt (or dec, decode, d). Encryption is the default when mode is omitted.

What happens if a keyword is empty?

Both key1 and key2 must be non-empty and contain at least one A–Z letter after filtering.

How are digraphs formed from the text?

Only alphabetic letters are kept (J maps to I). Letters are paired left to right; if the count is odd, X is appended before encryption or decryption.

Is four-square secure for real secrets?

No. It is a classical teaching cipher. Use modern authenticated encryption such as AES-GCM for real confidentiality.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/enc/four-square

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/enc/four-square \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text":"HELPME","key1":"EXAMPLE","key2":"KEYWORD"}'
{
  "text": "HELPME",
  "key1": "EXAMPLE",
  "key2": "KEYWORD"
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "enc.four_square",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Use it free in the browser for history-of-crypto lessons, digraph puzzle design, and reversible worksheet keys, or call the API at $0.002 per successful request when pipelines need reproducible four-square transforms without re-implementing the square layout.

What the four-square cipher is and what this tool returns

The JSON response includes result for the transformed uppercase string, encoding fixed to four_square, mode set to encrypt or decrypt, key1_letters and key2_letters showing the normalized keyword streams, unique-letter views of each key, normalized_input after extraction and padding, a padded flag, digraphs count, length fields, letters_processed, the alphabet string, the four flattened squares, and a formula string that restates the digraph mapping for documentation and tests. There is no streaming path and no silent fallback to Playfair or Vigenère: either you supply non-empty text with at least one letter and two keywords that each contain at least one letter, or the request fails with invalid_input. If you need AES, Vigenère, columnar transposition, or Morse, use those dedicated endpoints; this landing answers only the classical four-square digraph contract that crypto history chapters and CTF warm-ups already describe.

How text, keys, and mode are read and how results stay reproducible

Only alphabetic characters inside each key are kept, uppercased, and mapped with J to I; digits and symbols in a key are ignored. Every digraph is processed with the fixed square layout, so encrypting then decrypting with the same pair of keywords always restores the normalized padded letter stream. The preferred payload fields are text for the message, key1 and key2 for the two keywords, and optional mode for encrypt or decrypt. Text accepts aliases such as input, value, s, message, plaintext, and ciphertext so forms and SDK clients can reuse existing column names. Key1 accepts keyword1, key_1, k1, upper_key, and right_key; key2 accepts keyword2, key_2, k2, lower_key, and left_key. If after that filter no letter remains for either keyword, or if a keyword string is empty, the engine rejects the request with invalid_input and a clear message that the keyword must contain at least one A–Z letter. Mode defaults to encrypt when omitted and also accepts short aliases such as enc, encode, e for encrypt and dec, decode, d for decrypt; any other string fails validation. Missing text, empty text, text with no letters, non-string types, and unknown modes all raise invalid_input so a blank form does not look like a successful no-op. Pair the free browser run on this page with the priced API when you need the identical mathematical result inside an automated pipeline without re-implementing the four squares yourself. Invalid inputs return invalid_input and are not charged, which keeps validation cheap while successful transforms remain a fixed item price of $0.002.

Where four-square fits in lessons, puzzles, and test fixtures

On this page the work runs entirely in your browser; through the API each successful lookup costs $0.002, failed validation is not charged, and nothing is stored after the response returns. That split — free interactive exploration and a priced, identical API — matches the rest of the KIT tier-A catalog and lets you move from a classroom demo to an automated pipeline without changing the transformed result.

Deterministic CI fixtures

Generate reproducible four-square ciphertext and plaintext pairs for unit tests, golden files, and contract checks.

Read the full KIT documentation →