Add Playfair Cipher (#4988)

This commit is contained in:
Govind Gupta
2024-01-03 18:44:38 +05:30
committed by GitHub
parent a7d140a43e
commit 9bef5a169c
3 changed files with 169 additions and 0 deletions

View File

@ -0,0 +1,37 @@
package com.thealgorithms.ciphers;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
public class PlayfairTest {
@Test
public void testEncryption() {
PlayfairCipher playfairCipher = new PlayfairCipher("KEYWORD");
String plaintext = "HELLO";
String encryptedText = playfairCipher.encrypt(plaintext);
assertEquals("GYIZSC", encryptedText);
}
@Test
public void testDecryption() {
PlayfairCipher playfairCipher = new PlayfairCipher("KEYWORD");
String encryptedText = "UDRIYP";
String decryptedText = playfairCipher.decrypt(encryptedText);
assertEquals("NEBFVH", decryptedText);
}
@Test
public void testEncryptionAndDecryption() {
PlayfairCipher playfairCipher = new PlayfairCipher("KEYWORD");
String plaintext = "PLAYFAIR";
String encryptedText = playfairCipher.encrypt(plaintext);
String decryptedText = playfairCipher.decrypt(encryptedText);
assertEquals(plaintext, decryptedText);
}
}