public static String encrypt(String plainText) {
String s = plainText.toLowerCase();// Taking out upper cases
s = s.replaceAll("\\s","");//Taking out blank spaces
float squareRoot = (float) Math.sqrt(s.length());
int dimension = (int) Math.ceil(squareRoot);
int x = dimension;
int y = dimension;
char[][] box = new char [x][y];// This is the box: a 2 dimensional array
int counter = 0;
for(int i = 0; i<x; i++){
for(int j = 0; j<y; j++){
if(counter<s.length()){
box[i][j]= s.charAt(counter);
counter++;
}
}
}
java.util.Arrays.deepToString(box);
StringBuilder sb = new StringBuilder();
for(int j =0; j<y; j++){
for(int i = 0; i<x; i++){
sb.append(box[i][j]);
}
}
return (sb.toString());
}
public static String decrypt(String cypherText) {
String s = cypherText.toLowerCase();// Taking out upper cases
s = s.replaceAll("\\s","");//Taking out blank spaces
float squareRoot = (float) Math.sqrt(s.length());
int dimension = (int) Math.ceil(squareRoot);
int x = dimension;
int y = dimension;
char[][] box = new char [x][y];// This is the box: a 2 dimensional array
int counter = 0;
for(int i = 0; i<x; i++){
for(int j = 0; j<y; j++){
if(counter<s.length()){
box[i][j]= s.charAt(counter);
counter++;
}
}
}
java.util.Arrays.deepToString(box);
StringBuilder sb = new StringBuilder();
for(int i = 0; i<x; i++){
for(int j = 0; j<y; j++){
sb.append(box[i][j]);
}
}
return (sb.toString());
}