@Test public void runTest() { assertEquals("DDAVDXDXFFGVFFFXDXAG", Adfgvx.adfgvx("HELLOWORLD", Mode.ENCRYPT)); assertEquals("HELLOWORLD", Adfgvx.adfgvx("DDAVDXDXFFGVFFFXDXAG", Mode.DECRYPT)); }
public static String adfgvx(String inputText, final Mode mode) { try { inputText = inputText.toLowerCase(); String output = null; init(); if (mode == Mode.ENCRYPT) { Point p; StringBuilder res = new StringBuilder(); inputText = inputText.toLowerCase().replace("/[^a-z0-9]/g", ""); for (int i = 0; i < inputText.length(); i++) { if (inputText.charAt(i) == ' ') { res.append(inputText.charAt(i)); } else { p = findPos(inputText.charAt(i)); res.append(code[p.x]).append(code[p.y]); } } output = res.toString(); } if (mode == Mode.DECRYPT) { StringBuilder res = new StringBuilder(); Point p; for (int i = 0; i < inputText.length();) { if (inputText.charAt(i) == ' ') { res.append(inputText.charAt(i)); i++; } else { String codeInt = "ADFGVX".toLowerCase(); p = new Point(codeInt.indexOf(inputText.substring(i, i + 1)), codeInt.indexOf(inputText.substring(i + 1, i + 2))); res.append(substitute[p.x][p.y]); i = i + 2; } } output = res.toString().toUpperCase(); } return output; } catch (Exception e) { return e.toString(); } }
Adfgvx { public static String adfgvx(String inputText, final Mode mode) { try { inputText = inputText.toLowerCase(); String output = null; init(); if (mode == Mode.ENCRYPT) { Point p; StringBuilder res = new StringBuilder(); inputText = inputText.toLowerCase().replace("/[^a-z0-9]/g", ""); for (int i = 0; i < inputText.length(); i++) { if (inputText.charAt(i) == ' ') { res.append(inputText.charAt(i)); } else { p = findPos(inputText.charAt(i)); res.append(code[p.x]).append(code[p.y]); } } output = res.toString(); } if (mode == Mode.DECRYPT) { StringBuilder res = new StringBuilder(); Point p; for (int i = 0; i < inputText.length();) { if (inputText.charAt(i) == ' ') { res.append(inputText.charAt(i)); i++; } else { String codeInt = "ADFGVX".toLowerCase(); p = new Point(codeInt.indexOf(inputText.substring(i, i + 1)), codeInt.indexOf(inputText.substring(i + 1, i + 2))); res.append(substitute[p.x][p.y]); i = i + 2; } } output = res.toString().toUpperCase(); } return output; } catch (Exception e) { return e.toString(); } } }
Adfgvx { public static String adfgvx(String inputText, final Mode mode) { try { inputText = inputText.toLowerCase(); String output = null; init(); if (mode == Mode.ENCRYPT) { Point p; StringBuilder res = new StringBuilder(); inputText = inputText.toLowerCase().replace("/[^a-z0-9]/g", ""); for (int i = 0; i < inputText.length(); i++) { if (inputText.charAt(i) == ' ') { res.append(inputText.charAt(i)); } else { p = findPos(inputText.charAt(i)); res.append(code[p.x]).append(code[p.y]); } } output = res.toString(); } if (mode == Mode.DECRYPT) { StringBuilder res = new StringBuilder(); Point p; for (int i = 0; i < inputText.length();) { if (inputText.charAt(i) == ' ') { res.append(inputText.charAt(i)); i++; } else { String codeInt = "ADFGVX".toLowerCase(); p = new Point(codeInt.indexOf(inputText.substring(i, i + 1)), codeInt.indexOf(inputText.substring(i + 1, i + 2))); res.append(substitute[p.x][p.y]); i = i + 2; } } output = res.toString().toUpperCase(); } return output; } catch (Exception e) { return e.toString(); } }  }
Adfgvx { public static String adfgvx(String inputText, final Mode mode) { try { inputText = inputText.toLowerCase(); String output = null; init(); if (mode == Mode.ENCRYPT) { Point p; StringBuilder res = new StringBuilder(); inputText = inputText.toLowerCase().replace("/[^a-z0-9]/g", ""); for (int i = 0; i < inputText.length(); i++) { if (inputText.charAt(i) == ' ') { res.append(inputText.charAt(i)); } else { p = findPos(inputText.charAt(i)); res.append(code[p.x]).append(code[p.y]); } } output = res.toString(); } if (mode == Mode.DECRYPT) { StringBuilder res = new StringBuilder(); Point p; for (int i = 0; i < inputText.length();) { if (inputText.charAt(i) == ' ') { res.append(inputText.charAt(i)); i++; } else { String codeInt = "ADFGVX".toLowerCase(); p = new Point(codeInt.indexOf(inputText.substring(i, i + 1)), codeInt.indexOf(inputText.substring(i + 1, i + 2))); res.append(substitute[p.x][p.y]); i = i + 2; } } output = res.toString().toUpperCase(); } return output; } catch (Exception e) { return e.toString(); } }  void main(String[] args); static String adfgvx(String inputText, final Mode mode); }
Adfgvx { public static String adfgvx(String inputText, final Mode mode) { try { inputText = inputText.toLowerCase(); String output = null; init(); if (mode == Mode.ENCRYPT) { Point p; StringBuilder res = new StringBuilder(); inputText = inputText.toLowerCase().replace("/[^a-z0-9]/g", ""); for (int i = 0; i < inputText.length(); i++) { if (inputText.charAt(i) == ' ') { res.append(inputText.charAt(i)); } else { p = findPos(inputText.charAt(i)); res.append(code[p.x]).append(code[p.y]); } } output = res.toString(); } if (mode == Mode.DECRYPT) { StringBuilder res = new StringBuilder(); Point p; for (int i = 0; i < inputText.length();) { if (inputText.charAt(i) == ' ') { res.append(inputText.charAt(i)); i++; } else { String codeInt = "ADFGVX".toLowerCase(); p = new Point(codeInt.indexOf(inputText.substring(i, i + 1)), codeInt.indexOf(inputText.substring(i + 1, i + 2))); res.append(substitute[p.x][p.y]); i = i + 2; } } output = res.toString().toUpperCase(); } return output; } catch (Exception e) { return e.toString(); } }  void main(String[] args); static String adfgvx(String inputText, final Mode mode);  }