forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHillCipherTest.java
36 lines (26 loc) · 953 Bytes
/
HillCipherTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.thealgorithms.ciphers;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class HillCipherTest {
HillCipher hillCipher = new HillCipher();
@Test
void hillCipherEncryptTest() {
// given
String message = "ACT"; // Plaintext message
int[][] keyMatrix = {{6, 24, 1}, {13, 16, 10}, {20, 17, 15}}; // Encryption key matrix
// when
String cipherText = hillCipher.encrypt(message, keyMatrix);
// then
assertEquals("POH", cipherText);
}
@Test
void hillCipherDecryptTest() {
// given
String cipherText = "POH"; // Ciphertext message
int[][] inverseKeyMatrix = {{8, 5, 10}, {21, 8, 21}, {21, 12, 8}}; // Decryption (inverse key) matrix
// when
String plainText = hillCipher.decrypt(cipherText, inverseKeyMatrix);
// then
assertEquals("ACT", plainText);
}
}