ForHosting KIT · Developer Utilities

Hill cipher 3×3

With the key 6,24,1,13,16,10,20,17,15, the word ACT encrypts to POH: each block of three letters is multiplied by the key matrix modulo 26, so every output letter depends on three input letters. The inverse matrix for decrypting comes with it. 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
ACT
Key
6,24,1,13,16,10,20,17,15
Calculation mode
Encrypt
You get
Result
POH
Det
25
Det inv
25
Length
3

The 3×3 Hill cipher is a classical polygraphic substitution invented by Lester S. Hill that multiplies successive three-letter blocks by a three-by-three integer key matrix modulo twenty-six. Encryption maps plaintext vectors to ciphertext with C equals K times P mod 26; decryption multiplies by the modular inverse of K when the determinant is coprime with twenty-six. Unlike monoalphabetic maps such as Caesar or Atbash, each ciphertext letter depends on three plaintext letters, which blunts single-letter frequency analysis and makes the cipher a standard teaching step into linear algebra over modular rings. People use it for cryptanalysis homework, CTF warm-ups, linear-algebra demos, and puzzle books that need a reversible block cipher with a short numeric key. This capability accepts non-empty text, a nine-number key in row-major order, and an optional encrypt or decrypt mode; it returns the transformed letter stream plus the determinant, inverse matrix, padding count, and block count.

Validation rules, invertible matrices, and common pitfalls

The decisive product rule is that the key matrix must be invertible modulo twenty-six: gcd of the determinant reduced mod 26 with twenty-six must equal one so a modular inverse matrix exists. If det of K is even or shares the factor thirteen with twenty-six the map is not bijective and decryption would be impossible; the tool reports a non-invertible key matrix message instead of returning a one-way scramble.

Do not treat the output as encryption for confidentiality: the key space for small modular matrices is tiny by modern standards, known-plaintext attacks recover K from a few matching triples, and the product page should never market Hill as a security control for passwords, tokens, or personal data. Prefer this landing when the search intent is hill cipher 3x3, hill encrypt decrypt matrix, or three-by-three polygraphic cipher; affine and multiplicative answer single-letter modular maps, Playfair answers digraph squares, and Base64 answers encoding, so they stay separate tools.

When decrypting, use the same nine key numbers that produced the ciphertext and the same padding convention; a wrong matrix yields a different linear map that will not match the original plaintext.

Where the 3×3 version is used, and its limits

Call the free in-browser 3×3 Hill cipher for homework checks, lecture slides on matrices over Z twenty-six, CTF practice, and one-off encrypt or decrypt runs without writing modular matrix inverse code in every language. A typical classroom workflow shows that monoalphabetic ciphers are one-by-one maps, then introduces block multiplication with a fixed invertible matrix, computes det by hand, and verifies that only coprime determinants decrypt. Support playbooks can reverse lightly obfuscated notes that staff wrote with known teaching keys.

Puzzle sites can precompute answers for display and reveal them on demand with mode decrypt. Pair with frequency-analysis or other classical tools only when a later teaching step needs a different cipher family—keep the three-by-three Hill landing on its own SEO intent around nine-number matrix polygraphic substitution.

Linear algebra and cryptanalysis homework

Students encrypt short phrases with a known 3×3 matrix, compute det and inverse mod 26, then decrypt classmates' ciphertexts without installing a CAS.

CTF warm-ups and puzzle books

Challenge authors ship a nine-number key and a Hill ciphertext block; solvers recover the plaintext with mode decrypt when the matrix is invertible.

How do I encrypt text with the 3×3 Hill cipher?

The response result field holds the uppercase ciphertext letters.

How do I decrypt Hill ciphertext?

Send the ciphertext as text, the same nine key numbers used to encrypt, and mode decrypt (or decode). The result is the reconstructed letter stream when the key is invertible and matches.

What happens if the key matrix is not invertible?

The Hill map is only bijective when gcd(det(K) mod 26, 26) equals 1.

Is the 3×3 Hill cipher tool free?

The browser tool runs free on your device.

Is the Hill cipher secure encryption?

No. Hill is a classical polygraphic cipher for puzzles and teaching linear algebra, not confidentiality. Never use it for passwords or sensitive data.

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/hill-3x3

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/hill-3x3 \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text":"ACT","key":"6,24,1,13,16,10,20,17,15"}'
{
  "text": "ACT",
  "key": "6,24,1,13,16,10,20,17,15"
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "enc.hill_3x3",
  "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.

When the key matrix is not invertible modulo twenty-six the request fails with invalid_input and a clear non-invertible key matrix message.

How the 3×3 Hill map works and what the response contains

Encryption treats each Latin letter as a number from zero through twenty-five, groups the stream into successive triples, multiplies each column vector by the three-by-three key matrix K, and reduces every coordinate modulo twenty-six before writing capital letters back. Only A–Z and a–z participate: they are uppercased and non-letters are dropped so block alignment stays deterministic across spaces and punctuation. If the letter count is not a multiple of three the engine pads with the letter X at the end, which is the classical teaching convention for incomplete final blocks. Decryption recovers plaintext by computing the modular inverse matrix K inverse such that K times K inverse is the identity mod 26, then multiplying each ciphertext triple by that inverse. Send JSON with required string field text set to any non-empty message, required key carrying nine integers in row-major order as a comma-separated string, a flat array of nine numbers, or a nested three-by-three array, and optional mode defaulting to encrypt. Aliases input, value, s, message, plaintext, and ciphertext work for the body; matrix, key_matrix, k, and key_numbers alias the key; op, action, direction, and operation alias mode. On success the response includes result with the uppercase letter ciphertext or plaintext, mode normalized to encrypt or decrypt, key as a nested three-by-three matrix reduced mod 26, key_flat as the nine entries, key_inv as the inverse matrix used for decryption, det and det_inv for the determinant and its inverse mod 26, length equal to the original character count, letters_used after padding, padding count, blocks equal to letters_used divided by three, and method equal to hill_3x3 so clients can branch without sniffing shapes. Identical inputs always produce identical JSON because the path is pure modular arithmetic with no network, no random seed, and no wall clock.

Validation rules, invertible matrices, and common pitfalls

Missing text, non-string text, or an empty string all raise invalid_input and are not charged on the prepaid API after the engine rejects the request. A key with fewer or more than nine integers, non-integer entries, floats, or empty tokens also fails with invalid_input. Digits, spaces, and punctuation in the message body are ignored rather than encrypted, so only the letter stream shapes the block grid; if no letters remain after stripping, the request fails.

API usage, pricing, classroom workflows, and practical limits

Use the prepaid KIT API when a backend, serverless function, tutoring platform, or SDK needs a stable contract under balance at $0.002 per successful item; validation failures never consume balance after rejection. Authors shipping SDKs can map the result field straight into a copy button while key, key_inv, det, and method make OpenAPI examples self-explanatory. Keep payloads to ordinary text sizes appropriate for a Worker isolate item call; this tool is for messages and snippets, not multi-megabyte binary blobs.

Pipeline and CI fixtures

Scripts and continuous-integration tests pin deterministic Hill outputs and the non-invertible key matrix error so accidental inverse or determinant bugs fail fast.

Read the full KIT documentation →