I need to create a simple java program for the problem below with program notes
ID: 3638491 • Letter: I
Question
I need to create a simple java program for the problem below with program notes to help me see what is happening in each step:Create a Java program to decrypt the following text using a simple Substitution Cipher (Caesar Cipher, nothing fancy). Submit the completed .java program as your assignment. The program should take the text below (hard coded or as input), and a shift value as input.
Hints:
(int) will return the ascii value of a letter. Example: A turns into 65
(char) will return the character value of a number. Example: 65 turns into A
WKHQHZRUNLQJDQGFBEHUVHFXULWBGHSDUWPHQWDWURVHVWDWHF ROOHJHRIIHUVDFHUWLILFDWHSURJUDPLQLQIRUPDWLRQVHFXULWBDW DOOIHGHUDOWUDLQLQJOHYHOVWKHSURJUDPFHUWLILHVWKHVWXGH QWVVDWLVIBLQJSURJUDPUHTXLUHPHQWVDUHWUDLQHGWRWKHIHGH UDOQVWLVVLFQVVLVWDQGDUGVIRULQIRUPDWLRQVBVWHPVVHFXUL WBSURIHVVLRQDOVGHVLJQDWHGDSSURYLQJDXWKRULWLHVLQIRUPD WLRQVBVWHPVHFXULWBRIILFHUVVBVWHPVFHUWLILHUVDQGULVNDQ DOBVWUHVSHFWLYHOB
Explanation / Answer
please rate - thanks
the correct key is 3
import java.util.*;
public class decrypt
{
public static void main(String[] args)
{String input="WKHQHZRUNLQJDQGFBEHUVHFXULWBGHSDUWPHQWDWURVHVWDWHF ROOHJHRIIHUVDFHUWLILFDWHSURJUDPLQLQIRUPDWLRQVHFXULWBDW DOOIHGHUDOWUDLQLQJOHYHOVWKHSURJUDPFHUWLILHVWKHVWXGH QWVVDWLVIBLQJSURJUDPUHTXLUHPHQWVDUHWUDLQHGWRWKHIHGH UDOQVWLVVLFQVVLVWDQGDUGVIRULQIRUPDWLRQVBVWHPVVHFXUL WBSURIHVVLRQDOVGHVLJQDWHGDSSURYLQJDXWKRULWLHVLQIRUPD WLRQVBVWHPVHFXULWBRIILFHUVVBVWHPVFHUWLILHUVDQGULVNDQ DOBVWUHVSHFWLYHOB";
String decrypt;
char ch;
int i,key,v;
Scanner in=new Scanner(System.in);
System.out.print("Enter the key to use ");
key=in.nextInt();
decrypt="";
System.out.print("decrypted message: ");
for(i=0;i<input.length();i++)
{v=(input.charAt(i)-'A'-key)%26+'A';
if(v<'A') //need to wrap around
v+=26;
ch=(char)(v);
decrypt+=ch;
}
System.out.println(decrypt);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.