你的这个算法是取得一个String中每个字符的byte值,然后与255和运算,再将结果转换为十六进制的,最后将每步运算取得的值累加,返回该值

解决方案 »

  1.   

    也没什么难的吧, System.out.println(stmp);很显然是在数据库里记录了stmp值,不然真没法算了,既然有了stmp就好办了,那就让hs减stmp直到hs为0就可以了,这样就可以求出有多少stmp了,将每个stmp转换为2进制的,然后减255,按顺序排起来是不是就完了。
      

  2.   

    public class GetKey {
      public static String generateKey(String info){
        String hs="";
        String stmp="";
        byte[] b=info.getBytes();
        for (int n=0;n<b.length;n++) {
          System.out.println("b[" + n + "]:" + b[n] + ",Hex:" + Integer.toHexString(b[n]));
          stmp=(java.lang.Integer.toHexString(b[n] & 0XFF));
          System.out.println(stmp);
          hs=hs+stmp;
        }
        return hs;
      }
      public static String recover(String info) {  //还原
        String result="";
        String[] s=new String[info.length()/2];
        for(int i=0;i<s.length;i++) {
          s[i]=info.substring(i*2,i*2+2);
          char b = (char)Integer.valueOf(s[i],16).intValue();
          result+=b;
        }
        return result;
      }  
      public static void main(String[] args) {
        String out = generateKey("zxvcxnlihsd;afa'fkasdfkoeuA");
        System.out.println(out + ", length:" + out.length());
        System.out.println(recover(out));
      }
    }
      

  3.   

    public class Key{public static String generateKey(String info){
        String hs="";
        String stmp="";
        byte[] b=info.getBytes(); for (int n=0;n<b.length;n++)
        {
          stmp=(java.lang.Integer.toHexString(b[n] & 0XFF));
          hs=hs+stmp;
          
          System.out.println("k: " + stmp);    }
        return hs;
      }
      
    public static String crackKey(String hs) {
    byte[] b = hs.getBytes();
    String info = "";

    for(int i=0;i<b.length;i=i+2)
    {
    byte[] bs = new byte[2];
    bs[0] = b[i];
    bs[1] = b[i+1];
    System.out.println("c: " + new String(bs));
    Integer temp = Integer.valueOf(new String(bs),16);
    info += (new Character((char)temp.intValue())).charValue();

    }

    return info;
    }public static void main(String[] args){

    String t = "1234567890";
    String m = Key.generateKey(t);
    System.out.println("key  :" + m);
    System.out.println("carck:" + Key.crackKey(m));

    }}
    我测试通过了,但是没优化,自己干吧,呵呵
      

  4.   

    中文解决public class Key{public static String generateKey(String info){
        String hs="";
        String stmp="";
        byte[] b=info.getBytes(); for (int n=0;n<b.length;n++)
        {
          stmp=(java.lang.Integer.toHexString(b[n] & 0XFF));
          hs=hs+stmp;
          
          System.out.println("k: " + stmp);    }
        return hs;
      }
      
    public static String crackKey(String hs) {
    byte[] b = hs.getBytes();
    byte[] t = new byte[b.length/2];
    String info = "";

    for(int i=0;i<b.length;i=i+2)
    {
    byte[] bs = new byte[2];
    bs[0] = b[i];
    bs[1] = b[i+1];
    System.out.println("c: " + new String(bs));
    Integer temp = Integer.valueOf(new String(bs),16);
    t[i/2] = temp.byteValue();
    }

    return new String(t);
    }public static void main(String[] args){

    String t = "&Icirc;&Ograve;&micro;&Auml;&sup2;&acirc;&Ecirc;&Ocirc;";
    System.out.println(t);
    String m = Key.generateKey(t);
    System.out.println("key  :" + m);
    System.out.println("carck:" + Key.crackKey(m));

    }}
      

  5.   

    把String t = "&Icirc;&Ograve;&micro;&Auml;&sup2;&acirc;&Ecirc;&Ocirc;";改为 String t = "我的测试";
      

  6.   

    楼上的是正确的,可以处理中文。
    一开始没有考虑中文问题,考虑不周啊,呵呵,现改之:public class GetKey {
      public static String generateKey(String info){
        String hs="";
        String stmp="";
        byte[] b=info.getBytes();    for (int n=0;n<b.length;n++) {
          System.out.println("b[" + n + "]:" + b[n] + ",Hex:" + Integer.toHexString(b[n]));
          stmp=(java.lang.Integer.toHexString(b[n] & 0XFF));
          System.out.println(stmp);
          hs=hs+stmp;
        }
        return hs;
      }
      public static String recover(String info) {
        String[] s=new String[info.length()/2];
        byte[] bt=new byte[info.length()/2];
        for(int i=0;i<s.length;i++) {
          s[i]=info.substring(i*2,i*2+2);
          bt[i]=Integer.valueOf(s[i],16).byteValue();    //可以处理中文
        }
        return new String(bt);
      }  
      public static void main(String[] args) {
        String out = generateKey("新年快乐!");
        System.out.println(out + ", length:" + out.length());
        System.out.println(recover(out));
      }
    }
      

  7.   

    多谢各位回贴,小弟在此拜谢,特别是advanced(超越) 和 Danger2000(飞鱼) 
      

  8.   

    package z1.sony;/**
     * @author kkk
     *
     * To change the template for this generated type comment go to
     * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
     */
    public class TestDecode {
    public static void main(String[] args){
    TestDecode td = new TestDecode();
    td.decodeHex("31323334353637387172737475767778797a7b7c7d7e");
    }
    private String decodeHex(String tmp) {
    StringBuffer sb = new StringBuffer(tmp);
    String[] strArrays = new String[sb.length() / 2];
    String str[] = new String[sb.length() / 2];
    StringBuffer tmpSb = new StringBuffer();
    for (int i = 0; i < sb.length() / 2; i++) {
    strArrays[i] = sb.substring(2 * i, 2 * i + 2);
    String bb = Integer.valueOf(strArrays[i], 16).toString();
    byte[] bytes = { new Byte(bb).byteValue()};
    str[i] = new String(bytes);
    tmpSb.append(str[i]);
    }
    System.out.println(tmpSb);
    return tmpSb.toString();
    }
    }
      

  9.   

    to cmcfeng (荷风) :
    客气了!呵呵:)