1 19 20 21 package org.apache.cayenne.conf; 22 23 34 public class Rot47PasswordEncoder implements PasswordEncoding 35 { 36 39 public String decodePassword(String encodedPassword, String salt) 40 { 41 return rotate(encodedPassword); 42 } 43 44 47 public String encodePassword(String normalPassword, String salt) 48 { 49 return rotate(normalPassword); 50 } 51 52 64 public String rotate(String value) 65 { 66 int length = value.length(); 67 StringBuffer result = new StringBuffer (); 68 69 for (int i = 0; i < length; i++) 70 { 71 char c = value.charAt(i); 72 73 if (c != ' ') 75 { 76 c += 47; 78 79 if (c > '~') 87 c -= 94; 88 } 89 90 result.append(c); 91 } 92 93 return result.toString(); 94 } 95 96 104 public static void main(String [] args) 105 { 106 Rot47PasswordEncoder encoder = new Rot47PasswordEncoder(); 107 108 for (int i = 0; i < args.length; i++) 109 { 110 String string = args[i]; 111 112 System.out.println(encoder.rotate(string)); 113 } 114 } 115 } 116 | Popular Tags |