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...
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.
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...
Please show solution and comments for this data structure using java.​ Implement a program in Java...
Please show solution and comments for this data structure using java.​ Implement a program in Java to convert an infix expression that includes (, ), +, -, *,     and / to postfix expression. For simplicity, your program will read from standard input (until the user enters the symbol “=”) an infix expression of single lower case and the operators +, -, /, *, and ( ), and output a postfix expression.
4 Implement a Java program that meets the following requirements • You can use the Java...
4 Implement a Java program that meets the following requirements • You can use the Java standard sequence data structure API types for sets, lists, stack,queue and priority queue as needed. All are available in the java.util package, which you will want to import in your program. 1. Argue in code comments which data structure, stack or queue, you will use to implement this method. Implement a method which creates some String objects as food orders for a small restaurant,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT