- Notifications
You must be signed in to change notification settings - Fork20.4k
feat(ciphers): Add PermutationCipher implementation(enhance #6697)#6700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
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 explanationAlgorithm 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, paddingTests include: basic functionality, different key sizes, error validation,real-world examples, and edge case handling.
codecov-commenter commentedOct 7, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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
Please review@DenizAltunkapan@yanglbme@alxkm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Looks good, thanks.
c06dc29
intoTheAlgorithms:masterUh oh!
There was an error while loading.Please reload this page.
Thanks a lot@alxkm . |
Add PermutationCipher Implementation
Description
This PR adds a newPermutationCipher 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
IllegalArgumentException
messages✅ 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