feat(ciphers): Add PermutationCipher implementation(enhance #6697)#6700
Merged
alxkm merged 7 commits intoTheAlgorithms:masterfrom Oct 8, 2025
Merged
feat(ciphers): Add PermutationCipher implementation(enhance #6697)#6700alxkm merged 7 commits intoTheAlgorithms:masterfrom
alxkm merged 7 commits intoTheAlgorithms:masterfrom
Conversation
…e tests - Implement PermutationCipher class for transposition encryption/decryption - Add encrypt() and decrypt() methods with permutation key support - Include robust key validation (1-based positions, no duplicates) - Implement automatic padding for incomplete blocks using 'X' character - Add comprehensive error handling with descriptive exceptions - Create 20+ JUnit test cases covering encryption, decryption, edge cases - Support various key sizes and text processing (spaces removal, case handling) - Include detailed JavaDoc documentation with algorithm explanation Algorithm Details: - Divides plaintext into blocks based on key length - Rearranges characters within each block according to permutation positions - Supports round-trip encryption/decryption with inverse permutation - Handles edge cases: empty strings, single character keys, padding Tests include: basic functionality, different key sizes, error validation, real-world examples, and edge case handling.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6700 +/- ##
============================================
+ Coverage 75.88% 75.93% +0.04%
- Complexity 5819 5845 +26
============================================
Files 706 707 +1
Lines 19910 19965 +55
Branches 3859 3871 +12
============================================
+ Hits 15109 15160 +51
- Misses 4218 4219 +1
- Partials 583 586 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…itespace and comments
Contributor
Author
|
Please review @DenizAltunkapan @yanglbme @alxkm |
Contributor
Author
|
Thanks a lot @alxkm . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add PermutationCipher Implementation
Description
This PR adds a new PermutationCipher class to the ciphers package, implementing a transposition cipher that encrypts text by rearranging characters according to a fixed permutation key.
Algorithm Overview
The Permutation Cipher is a classic transposition cipher that:
Example: With key
{3, 1, 2}and plaintext "HELLO":Implementation Features
✅ Core Functionality
encrypt(String, int[])- Encrypts plaintext with permutation keydecrypt(String, int[])- Decrypts ciphertext using inverse permutation✅ Robust Validation
IllegalArgumentExceptionmessages✅ Comprehensive Testing
Files Added
src/main/java/com/thealgorithms/ciphers/PermutationCipher.java- Main implementationsrc/test/java/com/thealgorithms/ciphers/PermutationCipherTest.java- Comprehensive test suiteCode Quality
Testing Results