Hill Cipher Engine v3.0.0

Linear Algebra Cryptography Simulator

{{ totalBlocks }} Active Blocks
{{ mode === 'encrypt' ? 'PLAINTEXT' : 'CIPHERTEXT' }}

Input Message

Raw Length: {{ inputText.length }} Sanitized: {{ sanitizedInput.length }} letters
Padded text to multiple of {{ matrixSize }} with '{{ paddingChar }}' → {{ paddedInput }}
OUTPUT NODE

Result Message

Result will appear here block by block...
Decryption Note: Multiplying ciphertext blocks by the calculated Modular Inverse Decryption Matrix $K^{-1} \pmod{26}$.

Hill Cipher Engine Card

{{ isInvertible ? 'Invertible Key' : 'Warning: Not Invertible' }}

Current Mode: {{ mode.toUpperCase() }}

Key Metrics

Determinant {{ determinant }} gcd(det, 26) = {{ gcd(determinant, 26) }}
Mod Inverse {{ modularInverse !== null ? modularInverse : 'Ø' }} det⁻¹ mod 26
Block Matrix {{ matrixSize }}×{{ matrixSize }} size: {{ matrixSize }} letters
Block Index {{ animationState === 'idle' ? '0' : activeBlockIndex + 1 }}/{{ totalBlocks }} {{ animationState.toUpperCase() }}

Invalid Encryption Key Matrix

The matrix determinant modulo 26 is {{ determinant }}. To encrypt/decrypt using the Hill Cipher, the determinant must share no common factors with 26 (i.e. $\gcd(\det, 26)$ must be 1). Otherwise, the decryption matrix $K^{-1}$ will not exist. Go to the Matrix Config tab and load a valid preset or click random generate.

Animation Controller Speed: {{ animationSpeed }}ms / sub-step
div>
Speed Delay:

Vector Transformation Engine

Enter input message to start the simulation visualization.
1. Read Block
2. To Numbers
3. Multiply
4. Modulo 26
5. To Output
{{ mode === 'encrypt' ? 'Key Matrix K' : 'Decryption Matrix K⁻¹' }}
{{ val }}
×
Input Vector
{{ currentInputBlockChars[idx] }} {{ vVal }}
=
Output Vector
? {{ vVal }} {{ currentOutputBlockChars[idx] }}
<
Calculation Trace Block {{ activeBlockIndex + 1 }}
• Reading block characters:
Index {{ idx }} = {{ char }}
• Converting characters to numeric indices (A=0, B=1, ... Z=25):
Character '{{ char }}' → index: {{ charToNum(char) }}
• Multiplying matrix rows by input column vector:
Row {{ idx + 1 }}: Calculating row...
Y{{ idx + 1 }} = ({{ val }} × {{ currentInputVector[cIdx] }}) +
= {{ getProductSumTerm(idx) }} = {{ getProductSum(idx) }}
• Applying modulo 26 to the products:
Row {{ idx + 1 }} modulo 26:
{{ getProductSum(idx) }} mod 26 = {{ vVal }}
• Mapping numeric indices back to alphabet characters:
Index {{ vVal }} → character: {{ currentOutputBlockChars[idx] }}

Matrix Size & Value Editors

Editable Matrix
Inputs must be integers 0 - 25
<

Preset Keys

Calculated Inverse Matrix $K^{-1} \pmod{26}$ (Used for Decryption)

{{ val }}
Matrix Inversion Math:

Determinant: $\det = {{ determinant }}$. Inverse Det: $\det^{-1} \pmod{26} = {{ modularInverse }}$.

$K^{-1} = \det^{-1} \times \text{adjugate}(K) \pmod{26}$. This matrix decrypts the ciphered blocks back to cleartext.

Inverse matrix cannot be computed because the current key matrix is not invertible.

The Mathematics of Hill Cipher

The **Hill Cipher** is a polygraphic substitution cipher based on linear algebra, invented by Lester S. Hill in 1929. It encrypts groups of letters (blocks) simultaneously using matrix multiplication.

1. Encryption Equation:

C = (K × P) mod 26

Where K is the N×N key matrix, P is the plaintext block vector, and C is the resulting ciphertext block vector.

2. Decryption Equation:

P = (K-1 × C) mod 26

Where K-1 is the modular multiplicative inverse of the matrix K.

3. Invertibility Condition:

For the inverse matrix K-1 to exist modulo 26, the determinant of K must be coprime to 26:
det(K) ≠ 0
gcd(det(K), 26) = 1 (The determinant must not share factors with 26, meaning it cannot be divisible by 2 or 13).

Alphabet-to-Number Index Chart (A-Z)

{{ String.fromCharCode(64 + n) }}
{{ n - 1 }}

Quick Actions

Engine ID: HC-26-PRO Alphabet Size: 26 (A-Z)
Sim Engine Status: {{ animationState.toUpperCase() }}