Hill Cipher 2x2 Encryption & Decryption in Java

Опубликовано: 21 Апрель 2026
на канале: VoxelPixel
5,991
44

2x2 Hill Cipher in Java
00:09 - Modulo Function
00:42 - Encryption Function
01:44 - Message to 2x"message length / 2" matrix
04:36 - Key to 2x2 matrix
05:22 - Validating the key
05:31 - Finding determinant
06:12 - Multiplicative inverse
07:49 - Encryption Process
09:59 - Testing Encryption
10:18 - Decryption Function
10:41 - Adjugate Matrix
12:10 - Multiplying multiplicative inverse with adjugate matrix
13:07 - Decryption Process
13:38 - Testing Decryption
13:55 - Complete Code View

-*- Support on Patreon:   / voxelpixel  
-*- Source Code: https://github.com/VoxelPixel

hill cipher encryption and decryption using java programming language

Cipher Algorithm

Encryption
1. Convert message into pairs of 2 rows and multiple columns, number of columns is total length of message divided by 2
2. Take a 4 letter key and convert it into 2x2 matrix
3. Perform matrix multiplication between each row and column pair of message and 2x2 key matrix
4. Take modulo 26 of result to obtain cipher text letter

Decryption
1. Convert message into pairs of 2 rows and multiple columns, number of columns is total length of message divided by 2
2. Take a 4 letter key and convert it into 2x2 matrix
3. Find determinant of the key matrix
4. find multiplicative inverse of the determinant ofkey matrix
5. find adjugate matrix of key matrix
6. multiply multiplicative inverse of determinant with adjugate matrix and take mod 26 of result
7. Perform matrix multiplication between each row and column pair of message and 2x2 key matrix
8. Take modulo 26 of result to obtain cipher text letter