Question

In: Computer Science

Encode Diffie Hellamn exchange in software by writing a small program that accepts the values of...

Encode Diffie Hellamn exchange in software by writing a small program that accepts the values of p and g, and randomly generates the secret numbers SA and SB, and derives the Diffie Hellman secret.

Test it on the following examples:

p = 11, g = 13

p = 7, g = 17

p = 17, g = 13

Solutions

Expert Solution

please find the code in c


#include<stdio.h>
long int findKey(int a,int b,int mod)
{
long long int t;
if(b==1)
return a;
t=findKey(a,b/2,mod);
if(b%2==0)
return (t*t)%mod;
else
return (((t*t)%mod)*a)%mod;
}
long long int calculateKey(int a,int x,int n)
{
return findKey(a,x,n);
}
int main()
{
int n,g,x,a,y,b;

printf("Enter the value of p and g : ");
scanf("%d%d",&n,&g);

printf("Enter the value for x for first person");
scanf("%d",&x);
a=findKey(g,x,n);

printf("Enter value for y for second person");
scanf("%d",&y);
b=findKey(g,y,n);
printf("key for the first person is : %lld\n",findKey(b,x,n));
printf("key for the second person is : %lld\n",findKey(a,y,n));
return 0;
}
  


Related Solutions

Software Decode: Write a function that accepts an in-order array of unsigned integer values. The function...
Software Decode: Write a function that accepts an in-order array of unsigned integer values. The function shall then scan the array for a specific pattern: Three values contained within the array equally spaced 20 units apart. The function shall return the index position within the original array where the pattern begins or -1 if not present. Given the input array: data[] = {10,20,31,40,55,60,65525} The function shall return: 1 IN JAVA PLEASE
Initialize and Print an Array Write a program that accepts two integer values, called "arraySize" and...
Initialize and Print an Array Write a program that accepts two integer values, called "arraySize" and "multiplier", as user input. Create an array of integers with arraySize elements. Set each array element to the value i*multiplier, where i is the element's index. Next create two functions, called PrintForward() and PrintBackward(), that each accept two parameters: (a) the array to print, (b) the size of the array. The PrintForward() function should print each integer in the array, beginning with index 0....
Post a Python program that accepts at least three values as input, performs some computation and...
Post a Python program that accepts at least three values as input, performs some computation and displays at least two values as the result. The program must include an if statement that performs different computations based on the value of one of the inputs. Include comments in your program that describe what the program does. Also post a screen shot of executing your program on at least two test cases.
Post a Python program that accepts at least three values as input, performs some computation and...
Post a Python program that accepts at least three values as input, performs some computation and displays at least two values as the result. The program must include an if statement that performs different computations based on the value of one of the inputs. Include comments in your program that describe what the program does. Also post a screen shot of executing your program on at least two test cases. I would like to build a code along with these...
Post a Python program that accepts at least three values as input, performs some computation, and...
Post a Python program that accepts at least three values as input, performs some computation, and displays at least two values as the result. The program must include an if statement that performs different computations based on the value of one of the inputs. Include comments in your program that describe what the program does. I would like to see a program that is simple like BMI calculator or any other program that can be used in a real-life situation...
Suppose we are writing a C++ program for the sales department of a small company. The...
Suppose we are writing a C++ program for the sales department of a small company. The department has 4 sales person and is selling 5 products. The program will allow the input of each sale made (sales person, product, sales amount). The program will also allow a user to see the sales made by a particular sales person or the sales on a particular product. Requirement of the Program: 1. Using a 2-D array as a data structure for storing...
What common elements do the ElGamal cryptosystem and Diffie-Hellman key exchange share?
What common elements do the ElGamal cryptosystem and Diffie-Hellman key exchange share?
You are writing a small program that records a swimmers swim time for a 100 Free...
You are writing a small program that records a swimmers swim time for a 100 Free Style event, compares it to the best time, and displays back if swimmer improved or added time. The swim time is entered in seconds. Prompt user to enter their best time before an event and current swim time and then display message if user improved or added time and by how many seconds. It's c++ program and use iostream header.
1) type a complete, working, C++ program that accepts two integer values from the variable num3,...
1) type a complete, working, C++ program that accepts two integer values from the variable num3, and store num1 raised to the power num2 into the variable num4. Then output the values of the four variables each on a separate line, formatted and with an appropriate message for each.keyboard into the variables num1 and num2, include prompts, store the square root of their sum into the program :
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT