Skip to content

Hill Cipher Decoder

Encrypt or decrypt A-Z text with an invertible 2 by 2 Hill cipher matrix and an explicit modulo-26 convention.

Privacy: your files never leave your device. All processing happens locally in your browser.

How to use

  1. 1.Confirm that the exercise uses A=0 through Z=25, two-letter column vectors and X padding.
  2. 2.Enter the two matrix rows, choose encrypt or decrypt, and provide the A-Z message or ciphertext.
  3. 3.Run the conversion and compare a known pair such as HELP to HIAT before relying on longer output.

About Hill Cipher Decoder

Hill Cipher Decoder is an educational implementation of Lester Hill's algebraic cipher for two-letter blocks. Enter a 2 by 2 key matrix as two rows separated by a semicolon, choose encryption or decryption, and process alphabetic text entirely in the browser. The default key 3 3; 2 5 turns HELP into HIAT under the convention documented on this page.

The tool maps A to 0, B to 1, through Z to 25. It removes spaces, punctuation and digits, groups the remaining letters into column vectors of length two, multiplies each vector by the key matrix, and reduces both results modulo 26. Encryption adds one X only when normalized plaintext has odd length. It does not attempt to preserve formatting or infer whether a final X was padding.

Matrix convention matters. Some references place letter vectors in rows or arrange key values in a different order, producing different ciphertext from the same visible numbers. This page uses C = K times P with P as a column vector. For key rows a b; c d and pair x y, output is a*x+b*y followed by c*x+d*y, each reduced modulo 26.

Decryption requires an inverse matrix modulo 26. The determinant a*d-b*c must be coprime with 26; otherwise no unique inverse exists and multiple plaintext pairs can map to the same ciphertext. The interface rejects such keys instead of returning misleading text. Negative and large key entries are normalized into the range 0 through 25.

Ciphertext must contain an even number of normalized letters because every block contains two values. Plaintext may have odd length because encryption appends X. If an original message really ended in X, decryption cannot distinguish that character from padding. Record the original length in any controlled exercise rather than deleting a trailing X automatically.

The Hill cipher was historically important because it applied linear algebra to polygraphic substitution. It is not secure for modern confidentiality. Known plaintext reveals linear relationships, the alphabet and block size are small, and this page exposes the key directly. Never use it for passwords, tokens, personal information, files or production messages. Use a reviewed authenticated-encryption scheme such as AES-GCM for real security.

Eight independently calculated fixtures cover the default HELP example, odd-length padding, zero and maximum alphabet values, and three other invertible matrices. Every fixture is checked in both directions. Invalid determinants, odd ciphertext, empty normalized input and oversized messages are rejected. Input is capped at 100,000 letters to keep interaction responsive.

Use the page by confirming the other party's alphabet mapping, vector orientation, block size and padding rule. Enter exactly four whole-number key values, test a published known pair before processing a longer exercise, and compare normalized A-Z output. A mismatch usually means a convention difference rather than a browser arithmetic problem. The output contains only uppercase letters and intentionally omits removed presentation characters. Keep spacing separately if an exercise expects restored words; normalization cannot reproduce case, punctuation, accents or digits. The calculator also leaves a decrypted trailing X untouched because automatically removing it could destroy a real message character.

Methodology & sources

Letters map to 0..25 and form two-element column vectors. Encryption computes K times P modulo 26. Decryption multiplies by det(K)^-1 times the adjugate modulo 26 after proving gcd(det,26)=1.

Frequently asked questions

Encoding & Crypto guides

View all