0% found this document useful (0 votes)
3 views2 pages

Vigenere Cipher Decryption Guide

The document provides a Java program that implements the Vigenere cipher decryption method. It includes a function to decrypt a given ciphertext using a specified key, handling input from the user. The program outputs the decrypted plaintext after processing the ciphertext and key.

Uploaded by

srushtishinde341
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Vigenere Cipher Decryption Guide

The document provides a Java program that implements the Vigenere cipher decryption method. It includes a function to decrypt a given ciphertext using a specified key, handling input from the user. The program outputs the decrypted plaintext after processing the ciphertext and key.

Uploaded by

srushtishinde341
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

You might also like