Question

In: Computer Science

Implement a Java program for Diffie-Hellman manually insert p, g, a, and b to get shared...

Implement a Java program for Diffie-Hellman manually insert p, g, a, and b to get shared key.

Write a Java

Solutions

Expert Solution

I have included my code and screenshots in this answer. In case, there is any indentation issue due to editor, then please refer to code screenshots to avoid confusion.

--------------------solution.java-------------------

import java.util.*;
import java.math.BigInteger; //to stor big integers

public class solution{
   public static void main(String[] args){
       Scanner scan = new Scanner( System.in );
       System.out.print("\nEnter p: ");
       BigInteger p = scan.nextBigInteger(); //read p

       System.out.print("\nEnter g: ");
       BigInteger g = scan.nextBigInteger(); //read g

       System.out.print("\nEnter a: "); //read a
       int a = scan.nextInt();

       System.out.print("\nEnter b: "); //read b
       int b = scan.nextInt();

       BigInteger Shared_key = ((g.pow(a).mod(p)).pow(b)).mod(p); //shared key = g^(ab)mod(p)

       System.out.print("\nShared_key = " + Shared_key + "\n");
   }
}

--------------------Screenshots solution.java-------------------

--------------------Output------------------

----------------------------------------------------


I hope this helps you,

Please rate this answer if it helped you,

Thanks for the opportunity


Related Solutions

In the Diffie-Hellman key exchange, Alice sends g^x mod p to Bob, and Bob sends g^y...
In the Diffie-Hellman key exchange, Alice sends g^x mod p to Bob, and Bob sends g^y mod p to Alice. (1) How do they get a common secret? (2) Suppose an attacker is intercepting their communication, and gets to know g, p, and g^x mod p. Why can’t the attacker figure out x from these data?
Let’s assume A and B are creating a secret key using Diffie Hellman key exchange. Assume...
Let’s assume A and B are creating a secret key using Diffie Hellman key exchange. Assume q = 13 and A’s secret is 10 and B’s secret is 5. ⦁   Find all primitive roots of q = 13. (Show the table) ⦁   Find the secret key generated when the primitive root 6 is used. ⦁   Let’s say there is C, that uses a secret AC = 8 with A and secret BC = 12 with B. Find the shared keys...
JAVA Write a class to implement a list with the ability to insert a new item...
JAVA Write a class to implement a list with the ability to insert a new item at any location within the list, remove an item, and search for an item. The list should use a linked list implementation. This implementation should make use of a dummy node at the head of the list and should have explict references head and previous. Add a method to the list that inserts elements in acsending order assuming the list is already sorted before...
write C program to implement the priority queue with the operation insert
write C program to implement the priority queue with the operation insert
Write a C program to implement the priority queue with the operations insert and extractmax. Sample...
Write a C program to implement the priority queue with the operations insert and extractmax. Sample : ====Menu==== insert extractmax display exit Enter your choice: 1 Input a number: 2 enter any key to go to main menu ====Menu==== insert extractmax display exit Enter your choice: 1 Input a number: 4 enter any key to go to main menu ====Menu==== insert extractmax display exit Enter your choice: 1 Input a number: 6 enter any key to go to main menu...
Write a program in Java Design and implement simple matrix manipulation techniques program in java. Project...
Write a program in Java Design and implement simple matrix manipulation techniques program in java. Project Details: Your program should use 2D arrays to implement simple matrix operations. Your program should do the following: • Read the number of rows and columns of a matrix M1 from the user. Use an input validation loop to make sure the values are greater than 0. • Read the elements of M1 in row major order • Print M1 to the console; make...
Write a java program that prompt the user to insert last term’s courses and their individual...
Write a java program that prompt the user to insert last term’s courses and their individual mark and store them in an appropriate multidimensional array.
C language Write a program in C to implement Queue and its operation (like create, insert,...
C language Write a program in C to implement Queue and its operation (like create, insert, delete, search) using array data structure.
Java Write a menu driven program that implements the following linked list operations : INSERT (at...
Java Write a menu driven program that implements the following linked list operations : INSERT (at the beginning) INSERT_ALPHA (in alphabetical order) DELETE (Identify by contents, i.e. "John", not #3) COUNT CLEAR
Bank Accounts in Java! Design and implement a Java program that does the following: 1) reads...
Bank Accounts in Java! Design and implement a Java program that does the following: 1) reads in the principle 2) reads in additional money deposited each year (treat this as a constant) 3) reads in years to grow, and 4) reads in interest rate And then finally prints out how much money they would have each year. See below for formatting. Enter the principle: XX Enter the annual addition: XX Enter the number of years to grow: XX Enter the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT