Product Cipher
Product Cipher
Product Cipher
import java.util.*;
class ProductCipher {
System.out.println("Enter a number:");
// Substitution encryption
char c = substitutionInput.charAt(i);
substitutionOutput.append((char) (c+5));
System.out.println("\nSubstituted text:");
System.out.println(substitutionOutput);
// Transposition encryption
int modulus;
if((modulus = transpositionInput.length()%n) != 0) {
modulus = n-modulus;
transpositionInput += "/";
}
System.out.println("\nTransposition Matrix:");
char c = transpositionInput.charAt(i+(j*n));
System.out.print(c);
transpositionOutput.append(c);
System.out.println();
System.out.println(transpositionOutput);
// Transposition decryption
n = transpositionOutput.length()/n;
char c = transpositionOutput.charAt(i+(j*n));
transpositionPlaintext.append(c);
// Substitution decryption
char c = transpositionPlaintext.charAt(i);
plaintext.append((char) (c-5));
System.out.println("\nPlaintext:");
System.out.println(plaintext);
Output:
#Product Cipher
import java.util.*;
class ProductCipher {
System.out.println("Enter a number:");
// Substitution encryption
char c = substitutionInput.charAt(i);
substitutionOutput.append((char) (c+5));
System.out.println("\nSubstituted text:");
System.out.println(substitutionOutput);
// Transposition encryption
int modulus;
if((modulus = transpositionInput.length()%n) != 0) {
modulus = n-modulus;
// ‘modulus’ is now the number of blanks/padding (X) to be appended
transpositionInput += "/";
System.out.println("\nTransposition Matrix:");
char c = transpositionInput.charAt(i+(j*n));
System.out.print(c);
transpositionOutput.append(c);
System.out.println();
System.out.println(transpositionOutput);
// Transposition decryption
n = transpositionOutput.length()/n;
char c = transpositionOutput.charAt(i+(j*n));
transpositionPlaintext.append(c);
}
// Substitution decryption
char c = transpositionPlaintext.charAt(i);
plaintext.append((char) (c-5));
System.out.println("\nPlaintext:");
System.out.println(plaintext);
Output: