mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-12-19 07:00:35 +08:00
40 lines
1.3 KiB
Java
40 lines
1.3 KiB
Java
package com.thealgorithms.ciphers;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
public class AffineCipherTest {
|
|
|
|
@Test
|
|
public void testEncryptMessage() {
|
|
String plaintext = "AFFINE CIPHER";
|
|
char[] msg = plaintext.toCharArray();
|
|
String expectedCiphertext = "UBBAHK CAPJKX"; // Expected ciphertext after encryption
|
|
|
|
String actualCiphertext = AffineCipher.encryptMessage(msg);
|
|
assertEquals(expectedCiphertext, actualCiphertext, "The encryption result should match the expected ciphertext.");
|
|
}
|
|
|
|
@Test
|
|
public void testEncryptDecrypt() {
|
|
String plaintext = "HELLO WORLD";
|
|
char[] msg = plaintext.toCharArray();
|
|
|
|
String ciphertext = AffineCipher.encryptMessage(msg);
|
|
String decryptedText = AffineCipher.decryptCipher(ciphertext);
|
|
|
|
assertEquals(plaintext, decryptedText, "Decrypted text should match the original plaintext.");
|
|
}
|
|
|
|
@Test
|
|
public void testSpacesHandledInEncryption() {
|
|
String plaintext = "HELLO WORLD";
|
|
char[] msg = plaintext.toCharArray();
|
|
String expectedCiphertext = "JKZZY EYXZT";
|
|
|
|
String actualCiphertext = AffineCipher.encryptMessage(msg);
|
|
assertEquals(expectedCiphertext, actualCiphertext, "The encryption should handle spaces correctly.");
|
|
}
|
|
}
|