I am very new to programming and can't figure out the issue with my Cesar cipher my method for encryption works fine but my method for decryption is not working.
Main class
package com.company;
import java.util.Scanner;
public class Main {
public ceasarCipher ceasarCipher;
public static void main(String[] args) {
com.company.ceasarCipher utilityClass = new ceasarCipher();
int inShift;
String inString;
String encryptedString = "";
Scanner sca = new Scanner(System.in);
System.out.println("Please enter a string to encrypt");
inString = sca.nextLine();
System.out.println("=======================================================================================");
System.out.println("In this program");
System.out.println("Press 1 to encrypt your string by shifting it forward a certain amount");
System.out.println("Press 2 to decipher your string by shifting it backwards a certain amount");
System.out.println("Press 3 to give you all possible combinations of the shift in order to decipher");
System.out.println("Press 4 to exit the program");
System.out.println("=======================================================================================");
while(!sca.hasNext("x") && !sca.hasNext("X")){
int userInput;
userInput = sca.nextInt();
switch (userInput){
case 1:
System.out.println("Please enter the amount greater than 0 that you would like your String to be shifted forwards in order to encrypt it");
inShift = sca.nextInt();
System.out.println(utilityClass.ccEncrypt(inShift,inString));
case 2:
System.out.println("Please enter the amount greater than 0 that you would like your String to be shifted backwards in order to decipher it");
inShift = sca.nextInt();
System.out.println(utilityClass.ccDecipher(inShift,encryptedString));
}
}
}
}
Subclass with methods
package com.company;
/**
* Created by Jake on 14/04/2017.
*/
public class ceasarCipher {
private int maxVal = 26;
//private int inShift;
//private String inString;
private String letters = "abcdefghijklmnopqrstuvwxyz";
//-----------------------------------------------------------
public String ccEncrypt (int inShift, String inString) {
String encryptedString = "";
char modulo;
int pos;
inString = inString.toLowerCase();
for (int i = 0; i < inString.length(); i++) {
pos = letters.indexOf(inString.charAt(i));
modulo = this.letters.charAt((pos + inShift) % maxVal);
encryptedString += modulo;
}
return encryptedString;
}
//----------------------------------------------------------------------
public String ccDecipher (int inShift, String encryptedString) {
String decipheredString = "";
char modulo;
int pos;
for (int i = encryptedString.length() - 1; i >= 0; i--) {
pos = letters.indexOf(encryptedString.charAt(i));
modulo = this.letters.charAt((pos - inShift) % maxVal);
decipheredString += modulo;
}
return decipheredString;
}
// -----------------------------------------------------------------------
public void ccDecipherAll (String inString){
}
}