01: /*
02: DBPool - JDBC Connection Pool Manager
03: Copyright (c) Giles Winstanley
04: */
05: package snaq.db;
06:
07: /**
08: * Decodes passwords using the simple Rot13 algorithm.
09: * This algorithm is very insecure, but is included as an example.
10: * @author Giles Winstanley
11: */
12: public class RotDecoder implements PasswordDecoder {
13: private static final int offset = 13;
14:
15: public char[] decode(String encoded) {
16: return rot(encoded);
17: }
18:
19: private char[] rot(String encoded) {
20: StringBuffer sb = new StringBuffer(encoded);
21: for (int a = 0; a < sb.length(); a++) {
22: char c = sb.charAt(a);
23: if (c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z') {
24: char base = Character.isUpperCase(c) ? 'A' : 'a';
25: int i = c - base;
26: c = (char) (base + (i + offset) % 26);
27: sb.setCharAt(a, c);
28: }
29: }
30: char[] out = new char[sb.length()];
31: sb.getChars(0, out.length, out, 0);
32: return out;
33: }
34:
35: /* public static void main(String[] args) throws Exception
36: {
37: RotDecoder x = new RotDecoder();
38: System.out.println(x.rot(args[0]));
39: }*/
40: }
|