Can someone help me with Substitution cipher on Java ? | Sololearn: Learn to code for FREE!


Can someone help me with Substitution cipher on Java ?

If someone can help, please write me here​ or on an email [email protected]

3/21/2017 11:28:09 AM


12 Answers

New Answer


If I understand what you are saying, then just have the entire alphabet as a string. Then print the string starting from the position and then go back to the ASCII value of 'A' using a loop and a for loop to stop when you have gotten back to where you started. Or other implementations work, too.


So for deleting repeated letters, do you have to delete any repeated letter? I don't quite understand.


I would avoid using things in your code that are already defined. Like using array as the name of an array isn't a good idea. Instead, use a name that represents what the array holds. The same goes for array2, read as a string reader (name it what it should be reading), a scanner named in...


Okay. I have the alphabet and a keyword. And I have to input the keyword in certain position in the alphabet. If my position is 7 , it's​ should be like : STUVXZKEYWORDABCFGHIJLMNPQ


thanks guys. I appreciate your help. I will write back tomorrow, because now I have to go. :*


Hello. This is my cod : class SubCipher{ static String alphabetS="abcdefghijklmnopqrstuvwxyz"; public static int find(char[] c, char c2) { int w = 0; for(int i = 0; i < c.length; i++) { if(c[i] == (c2)) w = i; } return w; } public static String insert(String bag, String marble, int index) { String bagBegin = bag.substring(0,index); String bagEnd = bag.substring(index); return alphabetS=bagBegin + marble + bagEnd; } public static char[] convert(String g){ char[] array = new char[g.length()]; char[]array2=new char[g.length()]; StringReader read = new StringReader(g); try {; //Reads string into the array. Throws IOException } catch (IOException e) { e.printStackTrace(); } for (int i = 0; i < g.length(); i++) { array2[i]=array[i]; } return array2; } public static void main(String[]args){ Scanner in=new Scanner(; System.out.println(" plaintext: "); String plainText=in.nextLine(); System.out.println(" keyword: "); String keyword=in.nextLine(); System.out.println("position: "); int position=in.nextInt(); System.out.println(insert(alphabetS,keyword,position)); System.out.println(convert(alphabetS)); in.close(); } } Now I have to delete the repeated letters ,and put the keyword and the alphabet in a new array. This is my problem :(


I see. Thank you. But this wouldn't help me to solve the problem .


I have to input a keyword into the alphabet in a certain position without repeated letters. All letters must be 26.


STUVXZ'KEYWORD'ABCFGHIJLMNPQ This is how it should be. No repeated letters . Only 26 letters .( Alphabet-keyword-alphabet) = 26 no repeated letters.