Skip to content

Commit 2bd00f8

Browse files
authored
Update DiffieHellman.java
1 parent afdf7e4 commit 2bd00f8

File tree

1 file changed

+1
-42
lines changed

1 file changed

+1
-42
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
package com.thealgorithms.ciphers;
22

3-
import static org.junit.jupiter.api.Assertions.assertEquals;
4-
53
import java.math.BigInteger;
6-
import java.util.stream.Stream;
7-
8-
import org.junit.jupiter.params.ParameterizedTest;
9-
import org.junit.jupiter.params.provider.Arguments;
10-
import org.junit.jupiter.params.provider.MethodSource;
114

125
public final class DiffieHellman {
13-
6+
147
// Private constructor to prevent instantiation of utility class
158
private DiffieHellman() {
169
throw new UnsupportedOperationException("Utility class");
@@ -27,38 +20,4 @@ public static BigInteger calculateSharedSecret(BigInteger otherPublicValue, BigI
2720
// Returns b^x mod p or a^y mod p
2821
return otherPublicValue.modPow(secret, prime);
2922
}
30-
31-
// *********** Unit Test Section **************
32-
33-
// Method to provide test data for public key calculation
34-
private static Stream<Arguments> providePublicKeyData() {
35-
return Stream.of(
36-
// base, secret, prime, expected public value
37-
Arguments.of(new BigInteger("5"), new BigInteger("6"), new BigInteger("23"), new BigInteger("8")),
38-
Arguments.of(new BigInteger("2"), new BigInteger("5"), new BigInteger("13"), new BigInteger("6"))
39-
);
40-
}
41-
42-
// Test for public key calculation
43-
@ParameterizedTest
44-
@MethodSource("providePublicKeyData")
45-
public void testCalculatePublicValue(BigInteger base, BigInteger secret, BigInteger prime, BigInteger expected) {
46-
assertEquals(expected, DiffieHellman.calculatePublicValue(base, secret, prime));
47-
}
48-
49-
// Method to provide test data for shared secret calculation
50-
private static Stream<Arguments> provideSharedSecretData() {
51-
return Stream.of(
52-
// otherPublic, secret, prime, expected shared secret
53-
Arguments.of(new BigInteger("8"), new BigInteger("6"), new BigInteger("23"), new BigInteger("2")),
54-
Arguments.of(new BigInteger("6"), new BigInteger("5"), new BigInteger("13"), new BigInteger("12"))
55-
);
56-
}
57-
58-
// Test for shared secret calculation
59-
@ParameterizedTest
60-
@MethodSource("provideSharedSecretData")
61-
public void testCalculateSharedSecret(BigInteger otherPublicValue, BigInteger secret, BigInteger prime, BigInteger expected) {
62-
assertEquals(expected, DiffieHellman.calculateSharedSecret(otherPublicValue, secret, prime));
63-
}
6423
}

0 commit comments

Comments
 (0)