@@ -16,7 +16,6 @@ public final class ElGamalEncryption {
1616
1717 private static final SecureRandom RANDOM = new SecureRandom ();
1818
19- // Private constructor to prevent instantiation
2019 private ElGamalEncryption () {
2120 throw new UnsupportedOperationException ("Utility class" );
2221 }
@@ -27,25 +26,21 @@ private ElGamalEncryption() {
2726 * @param message the plaintext message to encrypt
2827 * @param bitLength the bit length for prime generation
2928 */
30- @ SuppressWarnings ({"PMD.SystemPrintln" , "PMD.DataflowAnomalyAnalysis" })
29+ @ SuppressWarnings ({ "PMD.SystemPrintln" , "PMD.DataflowAnomalyAnalysis" })
3130 public static void runElGamal (final String message , final int bitLength ) {
32- // Key generation
3331 final BigInteger p = BigInteger .probablePrime (bitLength , RANDOM );
3432 final BigInteger g = new BigInteger ("2" );
3533 final BigInteger x = new BigInteger (bitLength - 2 , RANDOM );
3634 final BigInteger y = g .modPow (x , p );
3735
38- // Encryption
3936 final BigInteger k = new BigInteger (bitLength - 2 , RANDOM );
4037 final BigInteger a = g .modPow (k , p );
4138 final BigInteger m = new BigInteger (message .getBytes ());
4239 final BigInteger b = (y .modPow (k , p ).multiply (m )).mod (p );
4340
44- // Decryption
4541 final BigInteger aInverse = a .modPow (p .subtract (BigInteger .ONE ).subtract (x ), p );
4642 final BigInteger decrypted = (b .multiply (aInverse )).mod (p );
4743
48- // Display results
4944 System .out .println ("Prime (p): " + p );
5045 System .out .println ("Generator (g): " + g );
5146 System .out .println ("Private Key (x): " + x );
0 commit comments