Question: Basically, I'm writing a program in Java which encrypts and decrypts messages using the Caesar cipher. However, it is extended so that it uses all

Basically, I'm writing a program in Java which encrypts and decrypts messages using the Caesar cipher. However, it is extended so that it uses all ASCII characters from 32-126. I am encrypting my messages just fine, but my decryption method doesn't work. Can someone please help me fix my program? I've attached my code below. Also just an FYI, the key is meant to be a constant (60).

package dshw1; import java.io.*; public class DSHW1 { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Input text to be encrypted."); String input = br.readLine(); char[] range = new char[95]; for(int i=0;i<95;i++) { range[i] = (char)(32+i); } String encrypted = encrypt(input, range); System.out.println(" Encrypted text: "+encrypted); String decrypted = decrypt(encrypted, range); System.out.println(" Decrypted text: "+decrypted); } static String encrypt(String input, char[] range) { char[] temp = new char[input.length()]; String encrypted = ""; temp = input.toCharArray(); for(int i=0;i

for(int i=0;i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!