Skip to content

Commit b9b5363

Browse files
authored
Update DiffieHellman.java
1 parent 998592d commit b9b5363

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/main/java/com/thealgorithms/ciphers/DiffieHellman.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
11
import java.math.BigInteger;
2-
import java.util.*;
2+
import java.util.Scanner;
33

44
public class DiffieHellman {
5+
private DiffieHellman() {
6+
throw new UnsupportedOperationException("Utility class");
7+
}
58
public static void main(String[] args) {
69
Scanner read = new Scanner(System.in);
710
System.out.println("Hello User! \nEnter your name:");
811
String name = read.nextLine();
912
read.nextLine();
1013
System.out.println("Welcome " + name + "!");
1114

12-
BigInteger n, g, x, y, k1, k2, A, B;
15+
BigInteger n;
16+
BigInteger g;
17+
BigInteger x;
18+
BigInteger y;
19+
BigInteger k1;
20+
BigInteger k2;
21+
BigInteger a;
22+
BigInteger b;
1323

1424
System.out.println("Enter two prime numbers: ");
1525
n = new BigInteger(read.next());
1626
g = new BigInteger(read.next());
1727

1828
System.out.println("Person A : Enter your secret number");
1929
x = new BigInteger(read.next());
20-
A = g.modPow(x, n);
30+
a = g.modPow(x, n);
2131

2232
System.out.println("Person B : Enter your secret number");
2333
y = new BigInteger(read.next());
24-
B = g.modPow(y, n);
34+
b = g.modPow(y, n);
2535

2636
k1 = B.modPow(x, n);
2737
k2 = A.modPow(y, n);

0 commit comments

Comments
 (0)