0% found this document useful (0 votes)
7 views1 page

Caesar Cipher Decryption Code

This document contains a Java program for decrypting messages using the Caesar Cipher method. It prompts the user to input a message and a key, then shifts each letter in the message backwards by the key value to produce the decrypted message. The program handles both lowercase and uppercase letters, while leaving non-alphabetic characters unchanged.
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)
7 views1 page

Caesar Cipher Decryption Code

This document contains a Java program for decrypting messages using the Caesar Cipher method. It prompts the user to input a message and a key, then shifts each letter in the message backwards by the key value to produce the decrypted message. The program handles both lowercase and uppercase letters, while leaving non-alphabetic characters unchanged.
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

Caesar Cipher - Decryption Code (Java)

package caesercipherdecryption;

import [Link];

public class Caesercipherdecryption {

public static void main(String[] args) {

String message, decryptedMessage = "";


int key;
char ch;

Scanner sc = new Scanner([Link]);

[Link]("Enter a message: ");


message = [Link]();

[Link]("Enter Key: ");


key = [Link]();

for (int i = 0; i < [Link](); i++) {


ch = [Link](i);

if (ch >= 'a' && ch <= 'z') {


ch = (char)(ch - key);
if (ch < 'a') {
ch = (char)(ch + 'z' - 'a' + 1);
}
decryptedMessage += ch;
}

else if (ch >= 'A' && ch <= 'Z') {


ch = (char)(ch - key);
if (ch < 'A') {
ch = (char)(ch + 'Z' - 'A' + 1);
}
decryptedMessage += ch;
}

else {
decryptedMessage += ch;
}
}

[Link]("Decrypted Message: " + decryptedMessage);


}
}

You might also like