Hill Cipher oleh Manisha Arie

Linear Algebra Cryptography Simulator

{{ mode === 'encrypt' ? 'PLAINTEXT' : 'CIPHERTEXT' }}

Static Result Preview

Configure key in Step 2 to see result... {{ staticOutput }} Key matrix is not invertible. Type input text to see result... Processing result...

Select Key Matrix Size

Choose the dimensions of the Hill Cipher key matrix.

Key Matrix Setup

Define the secret matrix coefficients of size {{ matrixSize }} × {{ matrixSize }}.

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

Values must be between 0 and 25 (A=0, Z=25).

{{ isInvertible && calculatedInverse ? calculatedInverse[rIdx][cIdx] : '?' }}

Auto-calculated for message decryption.

{{ isInvertible ? 'Key is ready for use!' : 'Key is not invertible.' }}

Determinant is not coprime to 26!

The current matrix determinant is {{ determinant }}. For decryption to be possible, the matrix must be invertible modulo 26, meaning gcd(determinant, 26) = 1. Currently gcd({{ determinant }}, 26) ≠ 1. Please choose invertible values or click the random generator button.

Inversion Math Status

det(K) {{ determinant }}
gcd(det, 26) 1
det⁻¹ mod 26 {{ modularInverse }}

Interactive Simulation Trace

Trace the matrix block multiplication step-by-step.

{{ totalBlocks }} Active Blocks Block {{ activeBlockIndex + 1 }} of {{ totalBlocks }} {{ mode.toUpperCase() }}
Vector Multiplication Layout
{{ mode === 'encrypt' ? 'Key Matrix K' : 'Inverse K⁻¹' }}
{{ val }}
×
Input Vector
{{ char }} {{ currentInputVector[idx] }}
=
Output Vector
{{ activeSubStep >= 4 ? currentOutputBlockChars[idx] : '_' }} {{ activeSubStep >= 3 ? currentOutputVector[idx] : '?' }}
Calculation Trace
Row {{ idx + 1 }} Multiplication Calculating... Computed
Y{{ idx + 1 }} = ({{ val }} × {{ currentInputVector[cIdx] }}) + = {{ getProductSumTerm(idx) }} = {{ getProductSum(idx) }}
Playback Center Speed: {{ animationSpeed }}ms
1. Read Block 2. A-Z → 0-25 3. Matrix Mult 4. Modulo 26 5. Out Char
Play Speed {{ animationSpeed }}ms

Accumulated Stream Result

Real-time simulation assembly

{{ finalOutput }} Pending animation start...

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 }}