AIM: - WAP to implement cryptanalysis or decoding using vigenere cipher.
import [Link];
public class VigenereCipherDecryption {
// Function to decrypt ciphertext using Vigenere Cipher
public static String decrypt(String ciphertext, String key) {
ciphertext = [Link]().replaceAll("[^A-Z]", "");
key = [Link]();
StringBuilder plaintext = new StringBuilder();
int keyIndex = 0;
for (int i = 0; i < [Link](); i++) {
char c = [Link](i);
// Shift value from key
int shift = [Link](keyIndex) - 'A';
// Decrypt: (cipher - shift + 26) mod 26
char decryptedChar = (char) (((c - 'A' - shift + 26) % 26) + 'A');
[Link](decryptedChar);
// Move to next key character
keyIndex = (keyIndex + 1) % [Link]();
}
return [Link]();
}
// Main method with user input
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter Ciphertext: ");
String ciphertext = [Link]();
[Link]("Enter Key: ");
String key = [Link]();
String plaintext = decrypt(ciphertext, key);
[Link]("Decrypted Plaintext: " + plaintext);
[Link]();
}
}
Ciphertext - lxfopvefrnhr
Key - lemon
Ciphertext - Vyc fnqkm spdpv nqo hjfxa qmcg mpm nrxn wwou
Key- cryptii