Skip to content

Commit e6afe1c

Browse files
committed
Fix PMD violations: remove unused parameter and main methods
1 parent 06e92d2 commit e6afe1c

2 files changed

Lines changed: 4 additions & 100 deletions

File tree

src/main/java/com/thealgorithms/backtracking/SudokuSolver.java

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -142,24 +142,4 @@ public static void printBoard(int[][] board) {
142142
System.out.println();
143143
}
144144
}
145-
146-
/**
147-
* Main method demonstrating Sudoku solver functionality.
148-
*
149-
* @param args command line arguments (not used)
150-
*/
151-
public static void main(String[] args) {
152-
int[][] board = {{5, 3, 0, 0, 7, 0, 0, 0, 0}, {6, 0, 0, 1, 9, 5, 0, 0, 0}, {0, 9, 8, 0, 0, 0, 0, 6, 0}, {8, 0, 0, 0, 6, 0, 0, 0, 3}, {4, 0, 0, 8, 0, 3, 0, 0, 1}, {7, 0, 0, 0, 2, 0, 0, 0, 6}, {0, 6, 0, 0, 0, 0, 2, 8, 0}, {0, 0, 0, 4, 1, 9, 0, 0, 5}, {0, 0, 0, 0, 8, 0, 0, 7, 9}};
153-
154-
System.out.println("Sudoku Puzzle:");
155-
printBoard(board);
156-
157-
if (solveSudoku(board)) {
158-
System.out.println("\nSolved Sudoku:");
159-
printBoard(board);
160-
} else {
161-
System.out.println("\nNo solution exists for this Sudoku puzzle.");
162-
}
163-
}
164-
}
165-
145+
}

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

Lines changed: 3 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.math.BigInteger;
44
import java.security.SecureRandom;
5-
import java.util.Random;
65

76
/**
87
* ElGamal Encryption Algorithm Implementation
@@ -113,7 +112,7 @@ public static KeyPair generateKeys(int bitLength) {
113112

114113
// Find a generator g (simplified: use a small generator that works for most primes)
115114
// In practice, we often use g = 2 or find a primitive root
116-
BigInteger g = findGenerator(p, random);
115+
BigInteger g = findGenerator(p);
117116

118117
// Generate private key x: random number in range [2, p-2]
119118
BigInteger x;
@@ -132,10 +131,9 @@ public static KeyPair generateKeys(int bitLength) {
132131
* Simplified approach: tries small values until finding a suitable generator
133132
*
134133
* @param p The prime modulus
135-
* @param random Random number generator
136134
* @return A generator g
137135
*/
138-
private static BigInteger findGenerator(BigInteger p, Random random) {
136+
private static BigInteger findGenerator(BigInteger p) {
139137
// Simplified: use 2 as generator (works for most safe primes)
140138
// For production, should verify g is a primitive root
141139
BigInteger g = BigInteger.valueOf(2);
@@ -255,78 +253,4 @@ public static String bigIntegerToString(BigInteger number) {
255253
}
256254
return new String(bytes);
257255
}
258-
259-
/**
260-
* Main method demonstrating ElGamal encryption and decryption
261-
*/
262-
public static void main(String[] args) {
263-
System.out.println("=== ElGamal Encryption Algorithm Demo ===\n");
264-
265-
// Example 1: Encrypting a small integer
266-
System.out.println("Example 1: Encrypting a small integer");
267-
System.out.println("--------------------------------------");
268-
269-
// Generate keys with 512-bit prime (use 1024 or 2048 for production)
270-
System.out.println("Generating keys (512-bit)...");
271-
KeyPair keyPair = generateKeys(512);
272-
273-
System.out.println("Prime (p): " + keyPair.getP());
274-
System.out.println("Generator (g): " + keyPair.getG());
275-
System.out.println("Private key (x): " + keyPair.getPrivateKey());
276-
System.out.println("Public key (y): " + keyPair.getPublicKey());
277-
278-
// Message to encrypt
279-
BigInteger message = BigInteger.valueOf(12345);
280-
System.out.println("\nOriginal message: " + message);
281-
282-
// Encrypt
283-
Ciphertext ciphertext = encrypt(message, keyPair);
284-
System.out.println("Encrypted: " + ciphertext);
285-
286-
// Decrypt
287-
BigInteger decrypted = decrypt(ciphertext, keyPair);
288-
System.out.println("Decrypted message: " + decrypted);
289-
290-
// Verify
291-
System.out.println("Decryption successful: " + message.equals(decrypted));
292-
293-
// Example 2: Demonstrating semantic security
294-
System.out.println("\n\nExample 2: Demonstrating Semantic Security");
295-
System.out.println("------------------------------------------");
296-
System.out.println("Same message encrypted twice produces different ciphertexts:");
297-
298-
Ciphertext ct1 = encrypt(message, keyPair);
299-
Ciphertext ct2 = encrypt(message, keyPair);
300-
301-
System.out.println("Encryption 1: " + ct1);
302-
System.out.println("Encryption 2: " + ct2);
303-
System.out.println("Are ciphertexts different? " + !ct1.getC1().equals(ct2.getC1()));
304-
305-
// Both decrypt to same message
306-
System.out.println("Both decrypt to: " + decrypt(ct1, keyPair) + " and " + decrypt(ct2, keyPair));
307-
308-
// Example 3: String encryption
309-
System.out.println("\n\nExample 3: Encrypting a String");
310-
System.out.println("-------------------------------");
311-
312-
String text = "Hello";
313-
System.out.println("Original text: " + text);
314-
315-
BigInteger textAsNumber = stringToBigInteger(text);
316-
System.out.println("Text as BigInteger: " + textAsNumber);
317-
318-
// Check if message is small enough
319-
if (textAsNumber.compareTo(keyPair.getP()) < 0) {
320-
Ciphertext textCiphertext = encrypt(textAsNumber, keyPair);
321-
System.out.println("Encrypted: " + textCiphertext);
322-
323-
BigInteger decryptedNumber = decrypt(textCiphertext, keyPair);
324-
String decryptedText = bigIntegerToString(decryptedNumber);
325-
System.out.println("Decrypted text: " + decryptedText);
326-
System.out.println("Match: " + text.equals(decryptedText));
327-
} else {
328-
System.out.println("Text too large for current key size. Use larger keys or split text.");
329-
}
330-
}
331-
}
332-
256+
}

0 commit comments

Comments
 (0)