mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-08 02:04:31 +08:00
Add Tests for HillCipher (#5562)
This commit is contained in:

committed by
GitHub

parent
389d1d70d5
commit
393337fa8e
36
src/test/java/com/thealgorithms/ciphers/HillCipherTest.java
Normal file
36
src/test/java/com/thealgorithms/ciphers/HillCipherTest.java
Normal file
@ -0,0 +1,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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user