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...
Translate the following steps into a Java program Get the monthly_fees Get the minutes Get the...
Translate the following steps into a Java program Get the monthly_fees Get the minutes Get the rate If minutes is less than or equal to 1000 then bill = monthly_fees Otherwise if minutes is between 1000 and 2000 (not including 1000) bill = (minutes - 1000)*rate + monthly_fees Otherwise bill = (minutes - 1000)*rate * 1.5 + monthly_fees Display “The bill is ” + bill Display “Thank you for using our program”
Write a JAVA program to modify the insert and remove of a binary search tree to...
Write a JAVA program to modify the insert and remove of a binary search tree to become an AVL tree.
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT