Skip to content

[OTHER] Java Implementation of Playfair Cipher #5026

@enrico-zini

Description

@enrico-zini

What would you like to share?

Issue:
https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/ciphers/ProductCipher.java
The shifting of the characters is constant, but it should be determined by user input.

Solution:
Substitute '5' for 'n'

Additional information

`System.out.println("Enter a number: ");
int n = sc.nextInt();

    // Substitution encryption
    StringBuffer substitutionOutput = new StringBuffer();
    for (int i = 0; i < substitutionInput.length(); i++) {
        char c = substitutionInput.charAt(i);
        substitutionOutput.append((char) (c + 5)); // <---- should be n instead of 5
    } ...
    StringBuffer plaintext = new StringBuffer();
    for (int i = 0; i < transpositionPlaintext.length(); i++) {
        char c = transpositionPlaintext.charAt(i);
        plaintext.append((char) (c - 5)); // <---- same here
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions