nikkkilll

soni5

Oct 3rd, 2019
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. Practical No : 05
  2. Aim :Write a program to implement the Diffie-Hellman Key Agreement algorithm to generate symmetric keys.
  3.  
  4. Input :
  5.  
  6. using System;
  7. usingSystem.Collections.Generic;
  8. usingSystem.Linq;
  9. usingSystem.Text;
  10. namespaceD_H_Algorithm
  11. {
  12. class Program
  13. {
  14. static void Main(string[] args)
  15. {
  16. int m1 = 1, m2 = 1, x, y, g, n;
  17. Console.Write("Enter G:");
  18. g = Convert.ToInt32(Console.ReadLine());
  19. Console.Write("Enter N:");
  20. n = Convert.ToInt32(Console.ReadLine());
  21. Console.Write("Enter x:");
  22. x = Convert.ToInt32(Console.ReadLine());
  23. Console.Write("Enter Y:");
  24. y = Convert.ToInt32(Console.ReadLine());
  25. for (inti = 0; i< x; i++)
  26. {
  27. m1 = m1 * g;
  28. }
  29. m1 = m1 % n;
  30. for (inti = 0; i< y; i++)
  31. {
  32. m2 = m2 * g;
  33. }
  34. m2 = m2 % n;
  35. Console.WriteLine("m1=\t" + m1 + "\n m2=\t" + m2);
  36.  
  37.  
  38. int k1 = 1, k2 = 1, a = m1, b = m2;
  39. m1 = m2 = 1;
  40. for (inti = 0; i< x; i++)
  41. {
  42. m1 = m1 * b;
  43. }
  44. k1 = m1 % n;
  45. for (inti = 0; i< y; i++)
  46. {
  47. m2 = m2 * a;
  48. }
  49. k2 = m2 % n;
  50. Console.WriteLine("k1=\t" + k1 + "\n k2=\t" + k2);
  51. Console.ReadKey();
  52. }
  53. }
  54. }
Add Comment
Please, Sign In to add comment