1 5 package snaq.db; 6 7 12 public class RotDecoder implements PasswordDecoder 13 { 14 private static final int offset = 13; 15 16 public char[] decode(String encoded) 17 { 18 return rot(encoded); 19 } 20 21 private char[] rot(String encoded) 22 { 23 StringBuffer sb = new StringBuffer (encoded); 24 for (int a = 0; a < sb.length(); a++) 25 { 26 char c = sb.charAt(a); 27 if (c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z') 28 { 29 char base = Character.isUpperCase(c) ? 'A' : 'a'; 30 int i = c - base; 31 c = (char)(base + (i + offset) % 26); 32 sb.setCharAt(a, c); 33 } 34 } 35 char[] out = new char[sb.length()]; 36 sb.getChars(0, out.length, out, 0); 37 return out; 38 } 39 40 45 } | Popular Tags |