public class Base643
{
public static final String BASE64CODE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
public static final String BASE64DECODE = "ABCDEGHIJKLMQRSTUVWXYZabcdefghijlmnopqrstwxyz0123456789.";
public static final int SPLIT_LINES_AT = 76;
    public Base643()
    {
    }    public static String encodebook(String s, int i, int j)
    {
       String s1 = s;
       if(s == null || s.length() < 10){ s1 = ""; }       StringBuffer stringbuffer = new StringBuffer();;       for(int l=0;l < s.length()/ 2;l++){
       stringbuffer.append(s.substring(1 + l * 2, 2 + l * 2));
       String s2 = stringbuffer.toString();
       String s3 = s2.substring(0, i);
       String s4;
       if(i > 0)
           s4 = (new StringBuilder(String.valueOf(s3))).append(".").append(s2.substring(i, s2.length() - j)).append(".").append(s2.substring(s2.length() - j)).toString();
       else
           s4 = (new StringBuilder(String.valueOf(s2.substring(i, s2.length() - j)))).append(".").append(s2.substring(s2.length() - j)).toString();
       s1 = s4;
    }
       return s1;
   }    public static void main(String[] args){ System.out.println("s1 = "+encodebook("kl4ofgsmgeje5gko99s1fc2ofm", 3, 3));}
}
报错结果为
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 3
at java.lang.String.substring(String.java:1935)
at com.Base643.encodebook(Base643.java:79)
at com.Base643.main(Base643.java:90)还有:我不确定for循环那里的条件是for(int l=0;l < s.length()/ 2;l++)还是for(int l=0;l >= s.length()/ 2;l++)
,当改为 >= 时貌似没有进入for?直接输出的是kl4ofgsmgeje5gko99s1fc2ofm

解决方案 »

  1.   

    其实这是反编译后的一个解密,但反编译出来的代码是被混淆了的,我自己改了一下,我改得可能也错了,我把反编译出来的结果也贴出来大家看看吧
    //public class Base643
    //{
    //
    // public Base643()
    // {
    // }
    //
    // public static String encodebook(String s, int i, int j)
    // {
    //     if(s != null && s.length() >= 10) goto _L2; else goto _L1
    //_L1:
    //     String s1 = "";
    //_L4:
    //     return s1;
    //_L2:
    //     int k;
    //     StringBuffer stringbuffer;
    //     int l;
    //     k = s.length();
    //     stringbuffer = new StringBuffer();
    //     l = 0;
    //_L5:
    //label0:
    //     {
    //         if(l < k / 2)                  
    //             break label0;
    //         String s2 = stringbuffer.toString();
    //         String s3 = s2.substring(0, i);
    //         String s4;
    //         if(i > 0)
    //             s4 = (new StringBuilder(String.valueOf(s3))).append(".").append(s2.substring(i, s2.length() - j)).append(".").append(s2.substring(s2.length() - j)).toString();
    //         else
    //             s4 = (new StringBuilder(String.valueOf(s2.substring(i, s2.length() - j)))).append(".").append(s2.substring(s2.length() - j)).toString();
    //         s1 = s4;
    //     }
    //     if(true) goto _L4; else goto _L3   
    //_L3:
    //     stringbuffer.append(s.substring(1 + l * 2, 2 + l * 2));
    //     l++;
    //       goto _L5
    // }
    //
    // public static byte[] zeroPad(int i, byte abyte0[])
    // {
    //     byte abyte1[] = new byte[i];
    //     System.arraycopy(abyte0, 0, abyte1, 0, abyte0.length);
    //     return abyte1;
    // }
    //
    // public static final String BASE64CODE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    // public static final String BASE64DECODE = "ABCDEGHIJKLMQRSTUVWXYZabcdefghijlmnopqrstwxyz0123456789.";
    // public static final int SPLIT_LINES_AT = 76;
    //}
      

  2.   

    s.substring(1 + l * 2, 2 + l * 2)
    里面的 2 + l * 2 > s.length,所以越界了
      

  3.   


    那么for循环那里其实应该是for(int l=0;l >= s.length()/ 2;l++)这样的对吧?可是也没出结果啊
      

  4.   

    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 3
    截取字符越界
    并且2楼已经说明原因..2楼+1