Java icon indicating copy to clipboard operation
Java copied to clipboard

[FEATURE REQUEST] <Java Implementation of Playfair Cipher>

Open amaan14999 opened this issue 2 years ago • 3 comments

What would you like to Propose?

Proposal: Addition of Playfair Cipher algorithm under, https://github.com/TheAlgorithms/Java/tree/master/src/main/java/com/thealgorithms/ciphers

Filename: PlayfairCipher.java

Overview

The Playfair Cipher, named after its inventor Sir Charles Wheatstone (but popularized by Lord Playfair), is a classical encryption technique that encrypts digraphs (pairs of letters) instead of individual letters. Its primary mechanism revolves around a 5x5 matrix, which serves as the key-table for both encryption and decryption.

Historical Context:

The Playfair Cipher was the first practical digraph substitution cipher and was used notably for tactical purposes during World War I and for lesser governmental purposes into the 20th century. Its strength lies in its ability to encrypt digraphs, which makes frequency analysis more challenging compared to monoalphabetic substitution ciphers.

More Details

https://en.wikipedia.org/wiki/Playfair_cipher

Issue details

Pseudo Code - Playfair Cipher

Function PlayfairCipher(Keyword):

    Matrix = Create5x5MatrixFrom(Keyword)

    Function Encrypt(Plaintext):
        Prepare Plaintext (uppercase, remove spaces, replace 'J' with 'I')
        For each digraph in Plaintext:
            Encrypt using Matrix and add to EncryptedText
        Return EncryptedText

    Function Decrypt(Ciphertext):
        For each digraph in Ciphertext:
            Decrypt using Matrix and add to DecryptedText
        Return DecryptedText

    Function Create5x5MatrixFrom(Keyword):
        Remove duplicates from Keyword and replace 'J' with 'I'
        Fill matrix with Keyword followed by remaining letters (skip 'J')
        Return Matrix

Key Features:

  1. 5x5 Key-table:

    • The cipher employs a 5x5 matrix filled with letters of the alphabet.
    • This matrix is constructed using a keyword (or keyphrase).
    • The keyword ensures letters in it appear only once, and 'I' and 'J' are typically combined to fit into a single cell.
  2. Digraph Substitution:

    • Plaintext is split into pairs of two letters (digraphs).
    • If a pair has two identical letters or the plaintext has an odd length, a filler letter, often 'X', is added.
  3. Encryption Rules:

    • Same Row: If both letters of a digraph are in the same row, each letter is replaced by the one immediately to its right, wrapping around if necessary.
    • Same Column: If both letters are in the same column, each letter is replaced by the one immediately below it, again wrapping around if needed.
    • Rectangle Formation: If the letters are on different rows and columns, a rectangle is formed using the two letters. Each letter of the digraph is then replaced by the letter in its same row but on the other horizontal side of the rectangle.
  4. Decryption is the Inverse:

    • The same rules apply for decryption, but in reverse. For instance, for letters in the same row, each letter is replaced by the one immediately to its left during decryption.

Additional Information

No response

amaan14999 avatar Oct 04 '23 05:10 amaan14999

Hello amaan14999, I am new to the open source. Is this a task to create a file named PlayfairCipher.java. If this is the case, please let me work out on this issue

shanu-user avatar Oct 07 '23 04:10 shanu-user

I am a student of cryptography and network security. I know this encryption algorithm and that too in JAVA. Please assign this issue to me.

govind516 avatar Jan 01 '24 18:01 govind516

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution!

github-actions[bot] avatar Feb 02 '24 00:02 github-actions[bot]

Please reopen this issue once you have made the required changes. If you need help, feel free to ask in our Discord server or ping one of the maintainers here. Thank you for your contribution!

github-actions[bot] avatar Feb 10 '24 00:02 github-actions[bot]