From f595b7a71ae99e341cf8d833a9ac58c2d9fdc4aa Mon Sep 17 00:00:00 2001 From: Aryansh Bhargavan Date: Thu, 5 Oct 2023 21:10:00 +0530 Subject: [PATCH 1/4] Feat: Added Vignere Cipher --- Ciphers/VignereCipher.php | 57 +++++++++++++++++++++++++++++ tests/Ciphers/VignereCipherTest.php | 19 ++++++++++ 2 files changed, 76 insertions(+) create mode 100644 Ciphers/VignereCipher.php create mode 100644 tests/Ciphers/VignereCipherTest.php diff --git a/Ciphers/VignereCipher.php b/Ciphers/VignereCipher.php new file mode 100644 index 00000000..1ced1ebc --- /dev/null +++ b/Ciphers/VignereCipher.php @@ -0,0 +1,57 @@ + diff --git a/tests/Ciphers/VignereCipherTest.php b/tests/Ciphers/VignereCipherTest.php new file mode 100644 index 00000000..6c738881 --- /dev/null +++ b/tests/Ciphers/VignereCipherTest.php @@ -0,0 +1,19 @@ +assertEquals($plaintext, $decryptedText); + } +} \ No newline at end of file From 1e039d22e5dbfdfb46623bfa7b3beff011f33624 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Thu, 5 Oct 2023 15:40:18 +0000 Subject: [PATCH 2/4] updating DIRECTORY.md --- DIRECTORY.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 2ee4e28e..a7b80c97 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -4,6 +4,7 @@ * [Caesarcipher](./Ciphers/CaesarCipher.php) * [Monoalphabeticcipher](./Ciphers/MonoAlphabeticCipher.php) * [Morsecode](./Ciphers/MorseCode.php) + * [Vignerecipher](./Ciphers/VignereCipher.php) * [Xorcipher](./Ciphers/XORCipher.php) ## Conversions @@ -89,6 +90,7 @@ * [Cipherstest](./tests/Ciphers/CiphersTest.php) * [Monoalphabeticciphertest](./tests/Ciphers/MonoAlphabeticCipherTest.php) * [Morsecodetest](./tests/Ciphers/MorseCodeTest.php) + * [Vignereciphertest](./tests/Ciphers/VignereCipherTest.php) * Conversions * [Conversionstest](./tests/Conversions/ConversionsTest.php) * Datastructures From 240260b21bbfb70f62e8a30a58763e98c2960932 Mon Sep 17 00:00:00 2001 From: Aryansh Bhargavan Date: Fri, 6 Oct 2023 21:48:11 +0530 Subject: [PATCH 3/4] Fix: Changes in formatting? --- Ciphers/VignereCipher.php | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/Ciphers/VignereCipher.php b/Ciphers/VignereCipher.php index 1ced1ebc..0dd1621f 100644 --- a/Ciphers/VignereCipher.php +++ b/Ciphers/VignereCipher.php @@ -1,22 +1,27 @@ +} \ No newline at end of file From 831d93b45430cb1082e09dcb8302b6f2cbdaa470 Mon Sep 17 00:00:00 2001 From: Aryansh Bhargavan Date: Fri, 6 Oct 2023 21:51:15 +0530 Subject: [PATCH 4/4] Fix: Changes in formatting? --- Ciphers/VignereCipher.php | 8 ++++---- tests/Ciphers/VignereCipherTest.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Ciphers/VignereCipher.php b/Ciphers/VignereCipher.php index 0dd1621f..d3bf1bf2 100644 --- a/Ciphers/VignereCipher.php +++ b/Ciphers/VignereCipher.php @@ -8,7 +8,7 @@ * @param string $key The encryption key. * @return string The encrypted text. */ -function vigenere_encrypt($plaintext, $key) +function vigenere_encrypt($plaintext, $key): string { // Convert the input to uppercase for consistency $plaintext = strtoupper($plaintext); @@ -39,13 +39,13 @@ function vigenere_encrypt($plaintext, $key) * @param string $key The decryption key. * @return string The decrypted text. */ -function vigenere_decrypt($ciphertext, $key) +function vigenere_decrypt($ciphertext, $key): string { $ciphertext = strtoupper($ciphertext); $key = strtoupper($key); $keyLength = strlen($key); $decryptedText = ""; - for ($i = 0; $i < strlen($ciphertext); $i++){ + for ($i = 0; $i < strlen($ciphertext); $i++) { $char = $ciphertext[$i]; if (ctype_alpha($char)) { // Calculate the shift based on the key @@ -60,4 +60,4 @@ function vigenere_decrypt($ciphertext, $key) } } return $decryptedText; -} \ No newline at end of file +} diff --git a/tests/Ciphers/VignereCipherTest.php b/tests/Ciphers/VignereCipherTest.php index 6c738881..37e572b8 100644 --- a/tests/Ciphers/VignereCipherTest.php +++ b/tests/Ciphers/VignereCipherTest.php @@ -16,4 +16,4 @@ public function testVignereCipher() $this->assertEquals($plaintext, $decryptedText); } -} \ No newline at end of file +}