Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Practical No : 05
- Aim :Write a program to implement the Diffie-Hellman Key Agreement algorithm to generate symmetric keys.
- Input :
- using System;
- usingSystem.Collections.Generic;
- usingSystem.Linq;
- usingSystem.Text;
- namespaceD_H_Algorithm
- {
- class Program
- {
- static void Main(string[] args)
- {
- int m1 = 1, m2 = 1, x, y, g, n;
- Console.Write("Enter G:");
- g = Convert.ToInt32(Console.ReadLine());
- Console.Write("Enter N:");
- n = Convert.ToInt32(Console.ReadLine());
- Console.Write("Enter x:");
- x = Convert.ToInt32(Console.ReadLine());
- Console.Write("Enter Y:");
- y = Convert.ToInt32(Console.ReadLine());
- for (inti = 0; i< x; i++)
- {
- m1 = m1 * g;
- }
- m1 = m1 % n;
- for (inti = 0; i< y; i++)
- {
- m2 = m2 * g;
- }
- m2 = m2 % n;
- Console.WriteLine("m1=\t" + m1 + "\n m2=\t" + m2);
- int k1 = 1, k2 = 1, a = m1, b = m2;
- m1 = m2 = 1;
- for (inti = 0; i< x; i++)
- {
- m1 = m1 * b;
- }
- k1 = m1 % n;
- for (inti = 0; i< y; i++)
- {
- m2 = m2 * a;
- }
- k2 = m2 % n;
- Console.WriteLine("k1=\t" + k1 + "\n k2=\t" + k2);
- Console.ReadKey();
- }
- }
- }
Add Comment
Please, Sign In to add comment