GalaxyPilot —— D.S


                  生命不熄,戰斗不止
          數據加載中……

          技術挑戰——根據編碼函數寫出解碼函數

          第一個粘出解碼函數的人將得到價值幾百美元的混淆工具,據評價也是目前最好的混淆器。當然,前題是你想要:)。

          public class Base64Coder
          {

              public static void main(String[] args)
              {
               String a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";//這里不技持中文
               String ru;
               char[] ch;
               try{
                byte[] bt= a.getBytes("UTF-8");
                ch = encrypt(bt);
                //ru = new String(decrypt(ch));
                System.out.println(ru);
               }catch(Exception e){}
              }
              public static char[] encrypt(byte abyte0[])
              {
                  int i = abyte0.length;
                  int j = (i * 4 + 2) / 3;
                  int k = ((i + 2) / 3) * 4;
                  char ac[] = new char[k];
                  int l = 0;
                  for(int i1 = 0; l < i; i1++)
                  {
                      int j1 = abyte0[l++] & 0xff;
                      int k1 = l >= i ? 0 : abyte0[l++] & 0xff;
                      int l1 = l >= i ? 0 : abyte0[l++] & 0xff;
                      int i2 = j1 >>> 2;
                      int j2 = (j1 & 3) << 4 | k1 >>> 4;
                      int k2 = (k1 & 0xf) << 2 | l1 >>> 6;
                      int l2 = l1 & 0x3f;
                      ac[i1++] = cChar[i2];
                      ac[i1++] = cChar[j2];
                      ac[i1] = i1 >= j ? '=' : cChar[k2];
                      i1++;
                      ac[i1] = i1 >= j ? '=' : cChar[l2];
                  }

                  return ac;
              }

              private static char cChar[];
              private static byte bByte[];

              static
              {
                  cChar = new char[64];
                  int i = 0;
                  for(char c = 'A'; c <= 'Z'; c++)
                      cChar[i++] = c;

                  for(char c1 = 'a'; c1 <= 'z'; c1++)
                      cChar[i++] = c1;

                  for(char c2 = '0'; c2 <= '9'; c2++)
                      cChar[i++] = c2;

                  cChar[i++] = '+';
                  cChar[i++] = '/';
                  bByte = new byte[128];
                  for(int j = 0; j < bByte.length; j++)
                      bByte[j] = -1;

                  for(int k = 0; k < 64; k++)
                      bByte[cChar[k]] = (byte)k;

              }
          }

          posted on 2007-10-12 09:49 舵手 閱讀(2118) 評論(10)  編輯  收藏

          評論

          # re: 技術挑戰——根據編碼函數寫出解碼函數  回復  更多評論   

          不容易哦
          2007-10-12 09:57 | 千里冰封

          # re: 技術挑戰——根據編碼函數寫出解碼函數  回復  更多評論   

          看代碼比較類,還是把代碼的原理寫出來.
          2007-10-12 12:28 | KF.咖啡

          # re: 技術挑戰——根據編碼函數寫出解碼函數  回復  更多評論   

          哈哈,寫出來那個挑個什么啊!過兩天發布解碼函數
          2007-10-12 13:13 | 舵手 QQ:8117892

          # re: 技術挑戰——根據編碼函數寫出解碼函數  回復  更多評論   

          呵呵 解碼 G_G
          這也被你整出來 !·#¥%……

          仔細看了下
          // 這好說 與 111.... 到時候 不變 到 j1
          // 還真玩人
          int j1 = abyte0[l++] & 0xff;

          //k1 ,l1 得到 0 或 abyte0[l++]
          int k1 = l >= i ? 0 : abyte0[l++] & 0xff;
          int l1 = l >= i ? 0 : abyte0[l++] & 0xff;

          // >>> ??什么東西 難道是 j1>> (>>2) ?
          //>> 是 和 除 /2 有點同 1101 >> 0110 : 1
          int i2 = j1 >>> 2;

          // ....... (無語)
          int j2 = (j1 & 3) << 4 | k1 >>> 4;
          int k2 = (k1 & 0xf) << 2 | l1 >>> 6;
          int l2 = l1 & 0x3f;
          //靜態塊中定義的 cChar 定義的 什么 A..Z 9..0 a..z
          ac[i1++] = cChar[i2];
          ac[i1++] = cChar[j2];
          // ..... 外頭的 l1 還是 不好好一步一步走的 !·#¥%……
          ac[i1] = i1 >= j ? '=' : cChar[k2];
          i1++;
          ac[i1] = i1 >= j ? '=' : cChar[l2];

          看來 我 好好當代碼工人把 (有點不干啊 )
          2007-10-12 17:03 | G_G

          # re: 技術挑戰——根據編碼函數寫出解碼函數  回復  更多評論   

          等 等
          java 好象是 16 為是吧
          那第一句的
          int j1 = abyte0[l++] & 0xff;
          只 給 后 面 8位與 前面的補0 也與
          !@#$%
          這怎么反 啊
          等結果
          2007-10-12 17:16 | G_G

          # re: 技術挑戰——根據編碼函數寫出解碼函數  回復  更多評論   

          貌似對了,大家幫忙測試一下吧。代碼寫的有點亂!
          private static byte[] decrypt(char[] ch) {

          int len = ch.length / 4 * 3;
          if(ch[ch.length - 1] == '=') len--;
          if(ch[ch.length - 2] == '=') len--;
          byte[] result = new byte[++len];
          for(int i = 0, j = 0; i < len; ) {

          int a = bByte[ch[j++]] & 0x3f;
          int b = bByte[ch[j++]] & 0x3f;
          result[i++] = (byte)(a << 2 | b >>> 4);
          if(ch[j] == '=') break;
          int c = bByte[ch[j++]] & 0x3f;
          result[i++] = (byte)(b << 4 | c >>> 2);
          if(ch[j] == '=') break;
          int d = bByte[ch[j++]] & 0x3f;
          result[i++] = (byte)(c << 6 | d);
          }

          return result;
          }
          2007-10-12 19:19 | lmatt

          # re: 技術挑戰——根據編碼函數寫出解碼函數  回復  更多評論   

          編碼的過程,應該是把3個字節轉成了4個字節。
          2007-10-12 19:28 | lmatt

          # re: 技術挑戰——根據編碼函數寫出解碼函數  回復  更多評論   

          lmatt果然很牛,試了一下是通過了。可以和我聯系一下,混淆器需要的話發給你。

          下面是我的解碼函數
          public static byte[] decrypt(char ac[])
          {
          int i = ac.length;
          if(i % 4 != 0)
          throw new IllegalArgumentException("Length of Base64 encoded input string is not a multiple of 4.");
          for(; i > 0 && ac[i - 1] == '='; i--);
          int j = (i * 3) / 4;
          byte abyte0[] = new byte[j];
          int k = 0;
          int l = 0;
          do
          {
          if(k >= i)
          break;
          char c = ac[k++];
          char c1 = ac[k++];
          char c2 = k >= i ? 'A' : ac[k++];
          char c3 = k >= i ? 'A' : ac[k++];
          if(c > '\177' || c1 > '\177' || c2 > '\177' || c3 > '\177')
          throw new IllegalArgumentException("Illegal character in Base64 encoded data.");
          byte byte0 = bByte[c];
          byte byte1 = bByte[c1];
          byte byte2 = bByte[c2];
          byte byte3 = bByte[c3];
          if(byte0 < 0 || byte1 < 0 || byte2 < 0 || byte3 < 0)
          throw new IllegalArgumentException("Illegal character in Base64 encoded data.");
          int i1 = byte0 << 2 | byte1 >>> 4;
          int j1 = (byte1 & 0xf) << 4 | byte2 >>> 2;
          int k1 = (byte2 & 3) << 6 | byte3;
          abyte0[l++] = (byte)i1;
          if(l < j)
          abyte0[l++] = (byte)j1;
          if(l < j)
          abyte0[l++] = (byte)k1;
          } while(true);
          return abyte0;
          }
          2007-10-13 08:44 | 舵手 QQ:8117892

          # re: 技術挑戰——根據編碼函數寫出解碼函數  回復  更多評論   

          在qq上加你為好友了
          2007-10-13 10:39 | lmatt

          # re: 技術挑戰——根據編碼函數寫出解碼函數  回復  更多評論   

          哇!是不容易也,lmatt就是牛!
          2007-10-20 02:00 | bigboy

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 阳原县| 扬州市| 桐梓县| 上饶市| 江孜县| 乌海市| 如皋市| 新郑市| 黑龙江省| 临高县| 清涧县| 内黄县| 肥东县| 昆山市| 高碑店市| 久治县| 巴东县| 武威市| 南昌市| 巴中市| 太谷县| 永修县| 新丰县| 盖州市| 平昌县| 武山县| 威海市| 修武县| 南丹县| 资阳市| 崇左市| 恩平市| 河南省| 潍坊市| 湖州市| 泰来县| 城步| 保山市| 贺州市| 沙洋县| 滕州市|