简单的字符转换和反转换函数

发表于:2007-07-04来源:作者:点击数: 标签:
加密解密时可以用到,只支持小写字母的转换。 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]

加密解密时可以用到,只支持小写字母的转换。

 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();
    }

原文转自:http://www.ltesting.net