Java icon indicating copy to clipboard operation
Java copied to clipboard

[FEATURE REQUEST] Add PermutationCipher implementation and tests

Open Chinmayeep58 opened this issue 1 year ago • 3 comments

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:

  1. Add PermutationCipher.java implementing the algorithm.
  2. Add PermutationCipherTest.java with unit tests for encryption/decryption.
  3. Include padding for incomplete blocks.

Additional Information

No response

Chinmayeep58 avatar Oct 07 '25 16:10 Chinmayeep58

Completed: https://github.com/TheAlgorithms/Java/pull/6700 PR

dheeraj1010 avatar Oct 07 '25 20:10 dheeraj1010

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.

avadhutmali avatar Oct 08 '25 06:10 avadhutmali

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. 🙂

dheeraj1010 avatar Oct 08 '25 06:10 dheeraj1010