标题:高手帮我看看吧,实在不知是哪里出问题了
只看楼主
lulu820830
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-3-24
 问题点数:0 回复次数:3 
高手帮我看看吧,实在不知是哪里出问题了
public class des3
{
    int[] IP={58,50,42,34,26,18,10,2,60,52,44,36,28,20,12,462,54,46,38,30,22,14,6,64,56,48,40,32,24,16,8,
                  57,49,41,33,25,17,9,1,59,51,43,35,27,19,11,3,61,53,45,37,29,21,13,5,63,55,47,39,31,23,15,7};
    char[] read(String s)   
                        {
                                    char[] a=new char[8];
                                    for(int i=0;i<8;i++)      
                               {
                                       a[i]=s.charAt(i);
                               }
                               return a;
                        }
                    
                    int[] jmsf(char[] y,char[] m)
                        {
                                    int[] erkey=new int[64];
                                    int[] erdata=new int[64];
                                    int[] dataip=new int[64];
                                    erkey=varyer(y);
                                    erdata=varyer(m);
                                    dataip=varyip(erdata);
                                    return dataip;
                        }
                        int[] varyip(int[] s)
                        {
                                    int[] m=new int[64];
                                    for(int i=0;i<64;i++)
                                    {
                                                m[i]=s[IP[i]-1];
                                    }
                                    return m;
                        }
                        int[] varyer(char[] s)
                        {
                                    int[] zcz=new int[64];   //存对应8个字符的64位二进制
                              for(int i=0;i<8;i++)
                              {
                                      for(int j=0;j<8;j++)
                                      {
                                          zcz[(i*8)+7-j]=s[i]%2;
                                          s[i]/=2;
                                      }
                               }
                               return zcz;
                        }
                        
                        public static void main(String[] args)
                        {
                                String zj="Asdfrthj";
                              String zj2="12345678";
                              des3 Des=new des3();
                              char[] mw=Des.read(zj);
                              char[] my=Des.read(zj2);
                              int[] shuchu=new int[64];
                            shuchu=Des.jmsf(my,mw);
                            System.out.println(shuchu);
               }
}

编绎能通过,运行就出现:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException:462
        at des3.varyip(des3.java:30)
        at des3.jmsf(des3.java:22)
        at des3.main(des3.java:56)

[[it] 本帖最后由 lulu820830 于 2008-4-12 19:29 编辑 [/it]]
搜索更多相关主题的帖子: int char String public 
2008-04-12 19:13
nima2004
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2007-11-26
得分:0 
for(int    i=0;i<64;i++){
    m[i]=s[IP[i]-1];
}
下标越界了。IP只有63个元素,而且其中有一个还是462。

[[it] 本帖最后由 nima2004 于 2008-4-12 21:18 编辑 [/it]]

我是新手,我谁都怕!
2008-04-12 21:03
lulu820830
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-3-24
得分:0 
回复 2# 的帖子
谢谢,我再回去看看

生命里的所有,不过是从得到失的过程
2008-04-13 16:48
lulu820830
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-3-24
得分:0 
回复 2# 的帖子
谢谢,我再回去看看

生命里的所有,不过是从得到失的过程
2008-04-13 16:49



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-208659-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.050038 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved