简单的字符转换和反转换函数
2008-01-05 08:27:02 来源:WEB开发网加密解密时可以用到,只支持小写字母的转换。
PRivate String dmix(String str1)
{
int MAX_COUNT = 20;
char ca[] = str1.toCharArray();
int count = 0;
for(int i = 0; i < ca.length; i++)
{
int a = ca[i] - count;
ca[i] = (char)a;
if(ca[i] < 'a')
ca[i] += '\032';
count = ++count % MAX_COUNT;
}
StringBuffer sb = new StringBuffer();
sb.append(ca);
return sb.toString();
}
public String mix(String str1)
{
int MAX_COUNT = 20;
char ca[] = str1.toCharArray();
int count = 0;
for(int i = 0; i < ca.length; i++)
{
int a=0;
a = ca[i] + count;
ca[i] = (char)a;
if(ca[i] > 'z')
ca[i] -= '\032';
count = ++count % MAX_COUNT;
}
StringBuffer sb = new StringBuffer();
sb.append(ca);
return sb.toString();
}
更多精彩
赞助商链接