+ 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
12 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.
+ 9
So for deleting repeated letters, do you have to delete any repeated letter? I don't quite understand.
+ 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...
+ 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
+ 1
thanks guys. I appreciate your help. I will write back tomorrow, because now I have to go. :*
+ 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 :(
+ 1
I see. Thank you. But this wouldn't help me to solve the problem .
0
I have to input a keyword into the alphabet in a certain position without repeated letters. All letters must be 26.
0
STUVXZ'KEYWORD'ABCFGHIJLMNPQ
This is how it should be. No repeated letters . Only 26 letters .( Alphabet-keyword-alphabet) = 26 no repeated letters.