Skip to content

Commit db4d4dc

Browse files
authored
Update DiffieHellmanTest.java
1 parent 1d2cc01 commit db4d4dc

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
1-
import static org.junit.jupiter.api.Assertions.assertEquals;
1+
package com.thealgorithms.ciphers;
22

3+
import org.junit.jupiter.api.Test;
4+
import static org.junit.jupiter.api.Assertions.*;
35
import java.math.BigInteger;
4-
import java.util.stream.Stream;
56

6-
import org.junit.jupiter.params.ParameterizedTest;
7-
import org.junit.jupiter.params.provider.Arguments;
8-
import org.junit.jupiter.params.provider.MethodSource;
7+
class DiffieHellmanTest {
98

10-
public class DiffieHellmanTest {
9+
@Test
10+
void testDiffieHellmanSharedKey() {
11+
BigInteger p = new BigInteger("23");
12+
BigInteger g = new BigInteger("5");
13+
BigInteger a = new BigInteger("6"); // Private key for Alice
14+
BigInteger b = new BigInteger("15"); // Private key for Bob
1115

12-
// Method to provide test data for public key calculation
13-
private static Stream<Arguments> providePublicKeyData() {
14-
return Stream.of(
15-
// base, secret, prime, expected public value
16-
Arguments.of(new BigInteger("5"), new BigInteger("6"), new BigInteger("23"), new BigInteger("8")),
17-
Arguments.of(new BigInteger("2"), new BigInteger("5"), new BigInteger("13"), new BigInteger("6"))
18-
);
19-
}
16+
DiffieHellman alice = new DiffieHellman(p, g, a);
17+
DiffieHellman bob = new DiffieHellman(p, g, b);
18+
19+
BigInteger A = alice.getPublicKey();
20+
BigInteger B = bob.getPublicKey();
2021

21-
// Test for public key calculation
22-
@ParameterizedTest
23-
@MethodSource("providePublicKey
22+
BigInteger aliceSharedKey = alice.computeSharedKey(B);
23+
BigInteger bobSharedKey = bob.computeSharedKey(A);
24+
25+
assertEquals(aliceSharedKey, bobSharedKey, "Shared keys do not match!");
26+
}
27+
}

0 commit comments

Comments
 (0)