[FEATURE REQUEST] Add PermutationCipher implementation and tests
What would you like to Propose?
Add a new cipher implementation- PermutationCipher.java, along with unit tests. I propose adding a Permutation Cipher class that performs encryption and decryption by rearranging characters of plaintext according to a fixed permutation key. This cipher is a simple transposition cipher useful for demonstrating permutation-based encryption logic. The implementation will include:
PermutationCipher.java: core class implementing encrypt/decrypt methods.
PermutationCipherTest.java: JUnit 5 test cases to verify correctness.
Issue details
Implement a cipher that encrypts text by rearranging the positions of letters based on a key permutation. For example, using key {3, 1, 2}, plaintext "HELLO" is divided into blocks of 3, and letters are permuted to produce ciphertext. Enhancements Proposed:
- Add PermutationCipher.java implementing the algorithm.
- Add PermutationCipherTest.java with unit tests for encryption/decryption.
- Include padding for incomplete blocks.
Additional Information
No response
Completed: https://github.com/TheAlgorithms/Java/pull/6700 PR
Hello Chinmayeep58,
This is an excellent proposal and would be a valuable addition to the ciphers collection. I would be happy to take on the implementation for this feature.
My plan for this contribution is as follows:
Core Implementation (PermutationCipher.java): I will develop the primary cipher class. This will include robust key validation in the constructor, proper handling of block padding for texts of any length, and efficient logic for both the encrypt and decrypt methods.
Unit Testing (PermutationCipherTest.java): I will create a comprehensive suite of unit tests using JUnit 5. The tests will verify the correctness of the encryption/decryption cycle, cover edge cases (such as empty strings), and ensure that invalid keys correctly throw an IllegalArgumentException.
Documentation (README.md): To ensure the contribution is educational, I will also include a brief README.md file explaining the algorithm with a clear example, consistent with the repository's standards.
This approach will ensure the final submission is complete, well-tested, and well-documented.
Could you please assign this issue to me? I am ready to begin working on it immediately.
Thank you.
Hi @avadhutmali , Thanks for your interest! I have already implemented this feature and raised a PR for this issue after thorough documentation and testing. It would be great if you could please look into another open issue to avoid duplicate work and save time. 🙂