Product Cipher (Java)

import java.util.*;

class ProductCipher {
public static void main(String args[]) {
System.out.println(“Enter the input to be encrypted:”);
String substitutionInput = new Scanner(;
System.out.println(“Enter a number:”);
int n = new Scanner(;

// Substitution encryption
StringBuffer substitutionOutput = new StringBuffer();
for(int i=0 ; i<substitutionInput.length() ; i++) {
char c = substitutionInput.charAt(i);
substitutionOutput.append((char) (c+5));
} Continue reading “Product Cipher (Java)”

Diffie Hellman Key Exchange Algorithm (Java)

import java.util.*; class DiffieHellman { public static void main(String args[]) { Scanner sc = new Scanner(; System.out.println(“Enter the value of Xa & Xb”); int Xa=sc.nextInt(); int Xb=sc.nextInt(); System.out.println(“Enter a Prime no. p”); int p=sc.nextInt(); System.out.println(“Enter Primitive Root a, such that a<p”); int a=sc.nextInt(); int Ya=(int)((Math.pow(a,Xa))%p); int Yb=(int)((Math.pow(a,Xb))%p); int Ka=(int)((Math.pow(Yb,Xa))%p); int Kb=(int)((Math.pow(Ya,Xb))%p); if(Ka==Kb) { System.out.println(“Transmission successful”); } else { System.out.println(“Transmission failed”); } } } Continue reading Diffie Hellman Key Exchange Algorithm (Java)