Skip to content

Commit 01f7449

Browse files
Merge branch 'master' into fix/adtfraction-normalization-overflow
2 parents 301a7f1 + 9918769 commit 01f7449

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

‎src/main/java/com/thealgorithms/ciphers/HillCipher.java‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.thealgorithms.ciphers;
22

3+
import com.thealgorithms.maths.GCD;
4+
35
public class HillCipher {
46

57
// Encrypts the message using the key matrix
@@ -75,15 +77,11 @@ public String decrypt(String message, int[][] inverseKeyMatrix) {
7577
// ciphertext and decryption becomes impossible.
7678
private void validateDeterminant(int[][] keyMatrix, int n) {
7779
int det = Math.floorMod(determinant(keyMatrix, n), 26);
78-
if (gcd(det, 26) != 1) {
80+
if (GCD.gcd(det, 26) != 1) {
7981
throw new IllegalArgumentException("Invalid key matrix. Determinant must be coprime with 26 to be invertible modulo 26.");
8082
}
8183
}
8284

83-
private int gcd(int a, int b) {
84-
return b == 0 ? a : gcd(b, a % b);
85-
}
86-
8785
// Computes the determinant of a matrix recursively
8886
private int determinant(int[][] matrix, int n) {
8987
int det = 0;

0 commit comments

Comments
 (0)