Question
Written in java When you have finished creating the alpha array and the random alpha array create methods to display the current cipher, accept a
Written in java
When you have finished creating the alpha array and the random alpha array create methods to display the current cipher, accept a new predefined cipher that will be loaded as the active cipher and then the encrypt and decrypt methods. Make a menu system to bring all the parts together.
So you create an array with the alphabet and then an encrypted version. The user can enter a sentence and then you return the encrypted code. They can also ask for the decrypted version. I need help adding the menu system, fixing the error, returning the encrypted code, encrypting the code, etc.
Heres what I have so far. There's an error thrown and it's not complete.
public class cipherciph { private String statement; public String go(String state) { statement = state; String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; String beta = ""; int n = 26; for (int j = 0; j int index = (int)(n * Math.random()); beta = beta + alpha.charAt(index); alpha = alpha.substring(0,index) + alpha.substring(index+1); n--; } int val1; String code = ""; for (int val = 0; val val1 = alpha.indexOf(statement.charAt(val)); code = Character.toString(beta.charAt(val1)); } return code; } }
Here's the runner:
import java.util.Scanner; public class cipherRun { public static void main( String[] args ) { cipherciph n = new cipherciph(); Scanner in = new Scanner (System.in); String statement = in.nextLine(); System.out.println (n.go(statement)); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started