java,对字符串(例:密码)进行加密解密,注意这个区分字符串大小写..........
加密-----------------------------------------------------------------------------
public String encodePWS(String SourceStr) {
String RetStr = "";
for (int i = 0; i <= SourceStr.length()-1; i++)
{
char c = SourceStr.charAt(i);
int h = (c >> 4) & 0xf;// 高4位
System.out.print(h);
int l = c & 0xf; // 低4位
RetStr = RetStr + (char)('a' + h) + (char)('a' + l);
}
System.out.println(RetStr.length());
return RetStr;
}
解密------------------------------------------------------------------------------
public String decodePWS(String SourceStr) {
String RetStr = "";
System.out.println(SourceStr+"------------------"+SourceStr.length());
for (int i = 0; i <= SourceStr.length()-1; i=i+2)
{
int h = SourceStr.charAt(i) - 'a';
System.out.print(h);
int l = SourceStr.charAt(i+1) - 'a';
System.out.print(l);
char c = (char) ((h << 4) + (l & 0xf));
RetStr = RetStr + c;
}
System.out.println("");
return RetStr;
}