You are viewing a single comment's thread. Return to all comments →
List<String> list=new ArrayList<>();
String x= s.replaceAll(" ", ""); int size=x.length(); double d=Math.sqrt(size); int rows=(int)Math.floor(d); int columns=(int)Math.ceil(d); int ref=columns; // System.out.println(d+" "+rows+" "+columns); StringBuffer sb=new StringBuffer();
for(int j=0; j<size;j++){ sb=sb.append(x.charAt(j)); if(j==ref-1){ ref +=columns; list.add(sb.toString()); sb.replace(0, sb.length(), ""); }else if(j==size-1){ list.add(sb.toString()); sb.replace(0, sb.length(), ""); } } // System.out.println(list); List<String> enc=new ArrayList<>(); for(int i=0;i<list.size();i++){ for(int j=0;j<list.get(i).length();j++){ if(i==0){ enc.add(String.valueOf(list.get(i).charAt(j))); }else { sb= sb.append(enc.get(j)); enc.set(j, sb.append(String.valueOf(list.get(i).charAt(j))).toString()); sb.replace(0, sb.length(), ""); } } } String result=""; for(String ss: enc){ result = result.concat(ss).concat(" "); } return result;
Seems like cookies are disabled on this browser, please enable them to open this website
Encryption
You are viewing a single comment's thread. Return to all comments →
Java
String x= s.replaceAll(" ", ""); int size=x.length(); double d=Math.sqrt(size); int rows=(int)Math.floor(d); int columns=(int)Math.ceil(d); int ref=columns; // System.out.println(d+" "+rows+" "+columns); StringBuffer sb=new StringBuffer();