Deffie-Hellman key exchange protocol is a method which allows two parties to establish a shared secret key (session key) over an insecure channel without having to send that key through the channel. This is achieved by using private and public keys.This key can then be used to encrypt the messages sent between those two parties using a symmetric key cipher.
The algorithm is as follows.
This is the complete code written in Java.
import java.math.BigInteger;
public class DH{
public static void main(String[] args){
BigInteger g=new BigInteger("5"); //Let g be 5(a primitive root modulo 23)
BigInteger p=new BigInteger("23"); //Let p be 23(a prime number)
if (args.length==1){
BigInteger privateKey=new BigInteger(args[0]); // Your Private key
BigInteger publicKey=g.modPow(privateKey,p); // Calculating the public key relevant to your private key
System.out.println("Public Key: "+publicKey.toString());
}
else if(args.length==2){
BigInteger privateKey=new BigInteger(args[0]); // Your Private key
BigInteger publicKey=new BigInteger(args[1]); // Public key of the other party
BigInteger sessionKey=publicKey.modPow(privateKey,p); // Calculating the session key
System.out.println("Session Key: "+sessionKey.toString());
}
else{
System.out.println("Please provide the valid number of arguments."); //If the correct number of arguments are not provided
}
}
}
This is a sample output that you get when running the program in command prompt in Windows.
When you give the private key of one party, it will calculate his/her public key.
Then when you give the private key of one party along with the public key of the other party, The session key(shared secret key) will be provided.
Note that this session key is the same for both parties. (It is not sent through the network, instead calculated by the 2 parties themselves.)
Thank you akke, me prashnema assignment ekakata dunna, mama mekama upload kala
ReplyDeleteApitath dunna ��
ReplyDeleteada dnna tyna ekaneh mee..
ReplyDeleteLike karanna thenak nathi nisa Share karala Comment ekak demma, Hebai den batch ekama plagiarism ahu weida danne na... Thank you so much. #UCSCපවුල
ReplyDeletePeya dekak late submission, hebai meka nattan ehemawat karanna hambawenne naha <3
ReplyDeleteVveomonat_ta_Bellevue Erica Parish https://wakelet.com/wake/Ys9LI-CUm-b_y1_h3X09k
ReplyDeleteeremousra
ponnaMguizu William Singleton click here
ReplyDeleteconhahoupo
juncpel0hiasa-1981 Robert Ritchie ReiBoot Pro
ReplyDeleteVisit
FonePaw
tlinbucktina
isthuthi akka
ReplyDelete