information security
information security
'C:\Users\ADARSH\AppData\Roaming\Code\User\workspaceStorage\d8a4d4e5d6a30892978430a025a0
bf4
0\redhat.java\jdt_ws\cf_fa686e5a\bin' 'BitwiseStringOperations'
'C:\Users\adarsh\AppData\Roaming\Code\User\workspaceStorage\d8a4d4e5d6a30892978430a025a0bf4
0\redhat.java\jdt_ws\cf_fa686e5a\bin' 'Main'
Enter a string: Adarsh
Combined Rails:
Arh
das
Interleaved format:
Adarsh
import java.util.*; public class
MD5HashCalculator { public static void
main(String[] args) {
Scanner scanner = new Scanner(System.in); // Scanner object for user input
// Prompt user to enter the text
System.out.print("Enter text to hash: ");
String text = scanner.nextLine(); // Fixed: using nextLine() instead of nextInt()
try {
String md5Hash = calculateMD5(text); // Call the hashing function
System.out.println("MD5 Hash: " + md5Hash); // Print the result
} catch (NoSuchAlgorithmException e) {
System.out.println("MD5 Algorithm not found."); // In case algorithm is not available
}
// ENCRYPTION
Cipher cipherEncrypt = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipherEncrypt.init(Cipher.ENCRYPT_MODE, secretKey);
byte[] encryptedBytes = cipherEncrypt.doFinal(plaintext.getBytes());
String ciphertextBase64 = Base64.getEncoder().encodeToString(encryptedBytes);
// DECRYPTION
Cipher cipherDecrypt = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipherDecrypt.init(Cipher.DECRYPT_MODE, secretKey);
byte[] decryptedBytes = cipherDecrypt.doFinal(encryptedBytes);
String decryptedText = new String(decryptedBytes);
// OUTPUT
System.out.println("Plaintext: " + plaintext);
System.out.println("Ciphertext (Base64): " + ciphertextBase64);
System.out.println("Decrypted Text: " + decryptedText);
}
}