Key Configuration

Plaintext

Ciphertext

Output:

Welcome to the Hill Cipher Tool!

The Hill cipher is a polygraphic substitution cipher based on linear algebra. Each letter is represented by a number, and a matrix is used as the key.

To Encrypt a Message:

  1. Set Matrix Size: Choose a size for the key matrix (e.g., 2 for a 2x2 matrix).
  2. Enter Key Matrix: Fill in the key matrix with numbers. The matrix must be invertible for decryption to be possible. You can also generate a random key.
  3. Enter Plaintext: Type the message you want to encrypt. It will be automatically padded if its length isn't a multiple of the matrix size.
  4. Click Encrypt: The encrypted message will appear in the "Output" box.

To Decrypt a Message:

  1. Set Matrix Size and Key: Use the same matrix size and key that were used for encryption.
  2. Enter Ciphertext: Paste the encrypted text into the "Ciphertext" field.
  3. Click Decrypt: The original message will be revealed in the "Output" box.

Note: The determinant of the key matrix must not be zero and must not share any common factors with 26 for the cipher to be decryptable.