1 19 20 21 package org.apache.cayenne.conf; 22 23 36 public class Rot13PasswordEncoder implements PasswordEncoding 37 { 38 41 public String decodePassword(String encodedPassword, String salt) 42 { 43 return rotate(encodedPassword); 44 } 45 46 49 public String encodePassword(String normalPassword, String salt) 50 { 51 return rotate(normalPassword); 52 } 53 54 66 public String rotate(String value) 67 { 68 int length = value.length(); 69 StringBuffer result = new StringBuffer (); 70 71 for (int i = 0; i < length; i++) 72 { 73 char c = value.charAt(i); 74 75 if ((c >= 'a' && c <= 'm') || (c >= 'A' && c <= 'M')) 77 c += 13; else if ((c >= 'n' && c <= 'z') || (c >= 'A' && c <= 'Z')) 79 c -= 13; 81 result.append(c); 82 } 83 84 return result.toString(); 85 } 86 87 95 public static void main(String [] args) 96 { 97 Rot13PasswordEncoder encoder = new Rot13PasswordEncoder(); 98 99 for (int i = 0; i < args.length; i++) 100 { 101 String string = args[i]; 102 103 System.out.println(encoder.rotate(string)); 104 } 105 } 106 } 107 | Popular Tags |