A Hill cipher decoder on iPhone can decrypt A–Z ciphertext in the browser by applying the modular inverse of a 2 by 2 key matrix modulo 26.
The Hill Cipher Decoder performs the conversion entirely in the browser, so a native iPhone app is unnecessary. The important part is matching the exercise’s alphabet mapping, vector direction, matrix layout, and padding rule; otherwise, even a valid key can produce a result that looks wrong.

Decode a Hill Cipher on Your iPhone
Use this workflow for a school exercise, ciphertext supplied with a matrix, or a known plaintext-ciphertext pair.
- Open the Hill Cipher Decoder page in the browser on your iPhone and locate the matrix, encryption or decryption mode, text input, and result areas.
- Confirm the conventions before entering data: A=0 through Z=25, two-letter column vectors, C = K × P modulo 26, and X padding for odd-length plaintext.
- Tap the matrix field and enter exactly four whole-number values as two rows separated by a semicolon. For the documented example, enter 3 3; 2 5. The semicolon distinguishes the first matrix row from the second.
- Choose Decrypt when working with ciphertext. Choose Encrypt when generating test ciphertext. Paste the A–Z text into the message area; spaces, punctuation, and digits are removed before processing.
- Check that the normalized ciphertext contains an even number of letters. Odd-length ciphertext is rejected because every ciphertext block must contain two values. Then run the conversion and read the uppercase result.
- Before processing a longer message, test the known pair. With the key entered as 3 3; 2 5, encrypting HELP produces HIAT, while decrypting HIAT reproduces HELP.
Keep the original message, its expected length, the matrix, and the selected mode in a separate record. The result contains only normalized cipher letters, so the tool cannot reconstruct the presentation details you need to restore afterward.
Match the Cipher’s Documented Conventions
The decoder uses one explicit set of rules rather than guessing which Hill cipher convention a source intended.
| Element | Rule used by the decoder |
|---|---|
| Letter values | A=0, B=1, and Z=25 |
| Block size | Two letters processed together |
| Vector direction | Plaintext and ciphertext use column vectors |
| Matrix relation | C = K × P modulo 26 |
| Key format | Four whole-number values in two semicolon-separated rows |
| Odd plaintext | Encryption appends one X after normalization |
| Output | Uppercase A–Z letters only |
Matrix convention matters even when the visible key numbers are identical. Some references arrange letter vectors as rows, use another A-to-number mapping, select a different block size, or apply a different padding rule. A source that places values in a different matrix order can therefore produce different ciphertext. Confirm all four settings before treating a mismatch as a calculation problem.
Confirm That the Matrix Can Be Inverted
For key rows a b; c d, the determinant is det(K) = ad − bc. A unique inverse modulo 26 exists only when det(K) is coprime with 26. When that condition is met, decryption uses the modular inverse of the key matrix: K^-1 ≡ det(K)^-1 [[d, −b], [−c, a]] modulo 26.
- A key with a determinant that is not coprime with 26 is rejected instead of returning misleading text.
- Without an invertible matrix, different plaintext pairs can map to the same ciphertext, so not every pair can be decrypted uniquely.
- Negative and large key entries are normalized into the range 0 through 25.
- Enter exactly four values in the stated row order; a valid matrix under one arrangement can represent a different matrix under another.
For a derivation of the inverse operation, see How to Decrypt a 2x2 Hill Cipher Using the mod 26 Inverse.
Run the HELP-to-HIAT Known-Pair Check
The documented key 3 3; 2 5 provides a quick orientation test. Under A=0 through Z=25, HELP becomes the pairs HE = (7, 4) and LP = (11, 15).
For the first pair, the encryption calculation is C = (3×7 + 3×4, 2×7 + 5×4) modulo 26 = (33, 34) modulo 26 = (7, 8), which maps to HI. For the second pair, C = (3×11 + 3×15, 2×11 + 5×15) modulo 26 = (78, 97) modulo 26 = (0, 19), which maps to AT. Together, the two blocks produce HIAT.
Run the reverse check as well: decrypting HIAT with the same key should recover HELP. If either direction disagrees, stop and check the alphabet mapping, matrix row order, and column-vector convention. A mismatch with a published example usually indicates a convention difference rather than an iPhone arithmetic problem.
Handle Padding and the Lost Presentation Layer
The decoder normalizes text before applying the matrix, so its output deliberately omits details that are not part of the cipher calculation.
- Spaces, punctuation, and digits are removed, and the remaining letters are grouped into two-letter blocks.
- Encryption appends one X only when the normalized plaintext has an odd number of letters.
- Decryption leaves a trailing X untouched because it cannot determine whether that character belonged to the original message or was added as padding.
- The output contains uppercase letters only; it does not preserve the input case, word spacing, punctuation, accents, or digits.
- Keep spacing separately if an exercise expects restored words, and record the original message length so a padded final X can be interpreted correctly.
If the original plaintext genuinely ended in X, deleting that letter automatically could change the message. Compare the result with the recorded length instead of assuming every final X came from padding.
Fix Input and Output Differences on iPhone
Most unsuccessful runs come from the shape of the input or a convention mismatch. Check these items before changing the key repeatedly.
- Key rejected: Confirm that the determinant is coprime with 26. The decoder will not process a non-invertible matrix.
- Odd ciphertext: Count the letters after spaces, punctuation, and digits have been removed. A valid ciphertext must have an even number of normalized letters.
- Empty normalized input: The message area needs at least one A–Z letter after non-letter characters are removed.
- Oversized input: The input is capped at 100,000 letters, and oversized messages are rejected.
- Unexpected output: Confirm that the semicolon is present, the mode is correct, and the exercise uses the same alphabet mapping, block size, vector orientation, and padding rule.
Uppercase-only output is expected. If the exercise needs spaces, punctuation, or original capitalization, save the normalized cipher result and restore those presentation elements separately only when you have a reliable record of where they belonged.
Use the Decoder for Education, Not Secrets
This Hill cipher implementation is an educational version of Lester Hill’s algebraic cipher, historically important because it applied linear algebra to polygraphic substitution. It is not secure for modern confidentiality: known plaintext can expose linear relationships, the alphabet and block size are small, and this page exposes the key directly.
Do not use the Hill cipher for passwords, tokens, personal information, files, or production messages. For real security, use a reviewed authenticated-encryption scheme such as AES-GCM. On iPhone, the browser workflow is suitable for classroom and historical-cipher exercises when those limits are understood.
If you're weighing options, Rail Fence Cipher Decoder on iPhone: Paste-and-Run Steps covers this in detail.