某家程式測試題-Java版

來源:互聯網
上載者:User

package pa;

public class Test
{
    public  static  void  encode(byte[]  in,  byte[]  out,  int  password)
    {
    int  len  =  in.length;

    int  seed  =  password  ^  0xeee3a8df;
    for  (int  i  =  0  ;  i  <  len;  ++i)  {
    byte  a  =  (byte)(  (  in[i]  ^  seed  )  >>>  3  );
    byte  b  =  (byte)(  (  (  ((int)in[i])  <<  12  )  ^  seed  )  >>>  (12-5)  );

    a  &=  0x1f;
    b  &=  0xe0;
    out[i]  =  (byte)(a  |  b);
    seed  =  (((seed  <<  7)  ^  seed  ^  out[i])  +  84723701);
    }
    }
    public  static  void  decode(byte[]  in,  byte[]  out,  int  password)
    {
    int  len  =  in.length;

    int  seed  =  password  ^  0xeee3a8df;
    for  (int  i  =  0  ;  i  <  len;  ++i)  {
    //  fill  the  code  here
        byte a=(byte)(in[i] & 0x1f);
        a=(byte)(a<<3);
        a=(byte)(a^seed);
        a=(byte)(a&248);
        
        byte b=(byte)(in[i]&0xe0);
        int temp=(int)b;
        temp=temp<<7;
        temp=temp^seed;
        temp=temp>>12;
        b=(byte)temp;
        b=(byte)(b&7);

        out[i]=(byte)(a  |  b);
        seed  =  (((seed  <<  7)  ^  seed  ^  in[i])  +  84723701);
        
    }
    }
    public  static  void  main(String  []  args)  throws  Exception
    {
    int  password  =  0xf6be2404;
    byte[]  buf1  =  {98,  127,  63,  59,  -43,  103,  -91,  80,  88,  -60,  -39,  18,  -81,  -10,  101,  -23,  -24,  -96,  -5,  56,  47,  50,  -1,  -69,  -85,  77,  -123,  35,  81,  104,  -67,  110,  97,  51,  42,  62,  -108,  -88,  -109,  -45,  63,  -81, 
106,  -118,  86,  -88,  31,  -120,  107,  106,  -104,  114,  -73,  30,  96,  97,  48,  -53,  114,  -45,  -86,  44,  -62,  1,  -53,  81,  90,  -7,  19,  -57,  109,  86,  };

    byte[]  buf2  =  new  byte[buf1.length];
    decode(buf1,  buf2,  password);
    System.out.println(new  String(buf2,  "GBK"));
    System.out.print("end");
    }
}

搜狗瀏覽器是目前速度最快、最穩定、最安全、功能最強大的“雙核”瀏覽器!!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.