OhMyCalc

Hill Cipher — Matrix Encryption

Encrypt text using the Hill cipher with a 2×2 or 3×3 key matrix. Based on linear algebra modulo 26. Includes matrix inverse for decryption.

How It Works

The Hill cipher multiplies a letter vector by the key matrix mod 26. For decryption, the modular inverse of the matrix is used.

How to Use the Hill Cipher — Matrix Encryption

  1. Enter or paste your text in the input field.
  2. The encoded or decoded result appears automatically.
  3. Copy the output using the copy button.
  4. Switch between encode and decode modes if available.

Riferimento Rapido

DaA
A65 (ASCII)
Z90 (ASCII)
a97 (ASCII)
048 (ASCII)
Space32 (ASCII)
@64 (ASCII)

Casi d'Uso

Formula

The Hill cipher multiplies a vector of letter indices (A=0…Z=25) by the key matrix modulo 26. Decryption uses the matrix inverse mod 26. The key matrix must be invertible mod 26.

Domande Frequenti

What is the Hill cipher?
The Hill cipher is a polygraphic substitution cipher based on linear algebra. It encrypts blocks of n letters by multiplying a vector of their indices (A=0…Z=25) by an n×n key matrix modulo 26.
What makes a key matrix valid?
The key matrix must be invertible modulo 26. This means its determinant must be coprime with 26 (i.e., gcd(det, 26) = 1). If the matrix is not invertible mod 26, decryption is impossible.
How does 2×2 vs 3×3 affect encryption?
A 2×2 matrix encrypts pairs of letters at a time; a 3×3 matrix encrypts triplets. Larger matrices provide better diffusion and stronger (though still breakable) encryption.
Why is padding added?
The plaintext length must be a multiple of the matrix size. If it is not, the letter X is appended until the length fits. This X padding is standard practice for the Hill cipher.
Can the Hill cipher be broken?
Yes. A known-plaintext attack can recover the key matrix with only n plaintext-ciphertext pairs (where n is the block size). Without knowing any plaintext, frequency analysis of blocks is used.