Back to Encryption Algorithms

Hill Cipher

About Hill Cipher

The Hill cipher is a polygraphic substitution cipher based on linear algebra, invented by Lester S. Hill in 1929. It operates on blocks of letters (typically 2 or 3 at a time) and uses matrix multiplication for encryption and matrix inversion for decryption.

How It Works:

  1. Choose a key matrix K of size n×n (typically 2×2 or 3×3).
  2. Convert the plaintext into numerical values (A=0, B=1, ..., Z=25).
  3. Divide the plaintext into blocks of size n.
  4. For each block, create a column vector and multiply it by the key matrix.
  5. Take modulo 26 of each resulting value.
  6. Convert the numerical values back to letters.

Mathematical Representation:

For encryption with a 2×2 matrix:

C = K × P (mod 26)

For decryption:

P = K-1 × C (mod 26)

Where:

  • C is the ciphertext vector
  • P is the plaintext vector
  • K is the key matrix
  • K-1 is the modular inverse of the key matrix

For the key matrix to be usable for decryption, it must be invertible in modulo 26 arithmetic. This means its determinant must not be zero and must be coprime with 26.

Hill Cipher Calculator

Encrypt and decrypt text using the Hill cipher

Determinant: 5

Invertible: Yes

Result will appear here

Security Considerations

The Hill cipher was a significant advancement in cryptography when it was introduced, but it has several security considerations:

  • It is vulnerable to known-plaintext attacks if enough plaintext-ciphertext pairs are available.
  • The cipher is completely linear, making it susceptible to linear algebra-based attacks.
  • It does not hide letter frequency patterns well in large texts.
  • Finding invertible matrices in modulo 26 can be challenging, as many matrices are not invertible in this context.
  • The key space, while large, is limited by the requirement that the key matrix must be invertible.

Despite these limitations, the Hill cipher was historically important as one of the first practical polygraphic ciphers and for introducing mathematical concepts to cryptography. Modern cryptographic systems have built upon these foundations to create more secure encryption methods.