Can someone help me with Substitution cipher on Java ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can someone help me with Substitution cipher on Java ?

If someone can help, please write me here​ or on an email strelecaaa@gmail.com

21st Mar 2017, 11:28 AM
strelecaaaa
strelecaaaa - avatar
9 Answers
+ 10
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.
22nd Mar 2017, 10:02 PM
J.G.
J.G. - avatar
+ 9
So for deleting repeated letters, do you have to delete any repeated letter? I don't quite understand.
23rd Mar 2017, 10:40 AM
J.G.
J.G. - avatar
+ 8
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...
23rd Mar 2017, 10:32 AM
J.G.
J.G. - avatar
+ 2
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
22nd Mar 2017, 9:56 PM
strelecaaaa
strelecaaaa - avatar
+ 1
thanks guys. I appreciate your help. I will write back tomorrow, because now I have to go. :*
22nd Mar 2017, 10:11 PM
strelecaaaa
strelecaaaa - avatar
+ 1
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 { read.read(array); //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.in); 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 :(
23rd Mar 2017, 10:26 AM
strelecaaaa
strelecaaaa - avatar
+ 1
I see. Thank you. But this wouldn't help me to solve the problem .
23rd Mar 2017, 10:39 AM
strelecaaaa
strelecaaaa - avatar
0
I have to input a keyword into the alphabet in a certain position without repeated letters. All letters must be 26.
22nd Mar 2017, 9:47 PM
strelecaaaa
strelecaaaa - avatar
0
STUVXZ'KEYWORD'ABCFGHIJLMNPQ This is how it should be. No repeated letters . Only 26 letters .( Alphabet-keyword-alphabet) = 26 no repeated letters.
23rd Mar 2017, 10:46 AM
strelecaaaa
strelecaaaa - avatar