⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainframe.java~292~

📁 DES加密算法实例1
💻 JAVA~292~
📖 第 1 页 / 共 2 页
字号:
    rs="";    mi=text.substring(0,8);    text=text.substring(8);    mitext="";    for(int n=0;n<=7;n++){    int c,temp;    String str="";     c=(byte)(mi.charAt(n));//    System.out.println(c);     while(c>0)     {temp=c%2;     if (temp==0){str='0'+str;}     else{str="1"+str;}     c=(c-temp)/2;     }    while(str.length()<8){str="0"+str;}//     System.out.println(str);     mitext=mitext+str;    }//System.out.println("mitext is "+mitext);//System.out.println("mi is "+mi+"!");//System.out.println(text+"!");mitext="0"+mitext;/////////////////////////////////////////////////////    ip=ip+    mitext.charAt(58)+mitext.charAt(50)+mitext.charAt(42)+mitext.charAt(34)+mitext.charAt(26)+mitext.charAt(18)+mitext.charAt    (10)+mitext.charAt(2)+    mitext.charAt(60)+mitext.charAt(52)+mitext.charAt(44)+mitext.charAt(36)+mitext.charAt(28)+mitext.charAt(20)+mitext.charAt    (12)+mitext.charAt(4)+    mitext.charAt(62)+mitext.charAt(54)+mitext.charAt(46)+mitext.charAt(38)+mitext.charAt(30)+mitext.charAt(22)+mitext.charAt    (14)+mitext.charAt(6)+    mitext.charAt(64)+mitext.charAt(56)+mitext.charAt(48)+mitext.charAt(40)+mitext.charAt(32)+mitext.charAt(24)+mitext.charAt    (16)+mitext.charAt(8)+    mitext.charAt(57)+mitext.charAt(49)+mitext.charAt(41)+mitext.charAt(33)+mitext.charAt(25)+mitext.charAt(17)+mitext.charAt(9)    +mitext.charAt(1)+    mitext.charAt(59)+mitext.charAt(51)+mitext.charAt(43)+mitext.charAt(35)+mitext.charAt(27)+mitext.charAt(19)+mitext.charAt    (11)+mitext.charAt(3)+    mitext.charAt(61)+mitext.charAt(53)+mitext.charAt(45)+mitext.charAt(37)+mitext.charAt(29)+mitext.charAt(21)+mitext.charAt    (13)+mitext.charAt(5)+    mitext.charAt(63)+mitext.charAt(55)+mitext.charAt(47)+mitext.charAt(39)+mitext.charAt(31)+mitext.charAt(23)+mitext.charAt    (15)+mitext.charAt(7);//System.out.println("ip is "+ip);li=ip.substring(0,32);ri=ip.substring(32);//System.out.println(li);//System.out.println(ri);li="0"+li;ri="0"+ri;for(int n=0;n<=15;n++){ re="";  k="";  rf="";  rs="";  rp="";//System.out.println("li is "+li);//System.out.println("ri is "+ri);  re=re+  ri.charAt(32)+ri.charAt(1)+ri.charAt(2)+ri.charAt(3)+ri.charAt(4)+ri.charAt(5)+  ri.charAt(4)+ri.charAt(5)+ri.charAt(6)+ri.charAt(7)+ri.charAt(8)+ri.charAt(9)+  ri.charAt(8)+ri.charAt(9)+ri.charAt(10)+ri.charAt(11)+ri.charAt(12)+ri.charAt(13)+  ri.charAt(12)+ri.charAt(13)+ri.charAt(14)+ri.charAt(15)+ri.charAt(16)+ri.charAt(17)+  ri.charAt(16)+ri.charAt(17)+ri.charAt(18)+ri.charAt(19)+ri.charAt(20)+ri.charAt(21)+  ri.charAt(20)+ri.charAt(21)+ri.charAt(22)+ri.charAt(23)+ri.charAt(24)+ri.charAt(25)+  ri.charAt(24)+ri.charAt(25)+ri.charAt(26)+ri.charAt(27)+ri.charAt(28)+ri.charAt(29)+  ri.charAt(28)+ri.charAt(29)+ri.charAt(30)+ri.charAt(31)+ri.charAt(32)+ri.charAt(1);//System.out.println("re is "+re);  k=key[n];//System.out.println(n+" key is "+k);  for(int m=1;m<=48;m++)  {if ((k.charAt(m-1)=='0')&&(re.charAt(m-1)=='0'))  {rf=rf+"1";} else {rf=rf+"0";}   }//System.out.println("rf is "+rf);for(int z=1;z<=8;z++)    {String sw="";      switch  (z)      { case 1: {sw=sw+rf.substring(0,6); break;}       case 2: {sw=sw+rf.substring(6,12); break;}       case 3: {sw=sw+rf.substring(12,18); break;}       case 4: {sw=sw+rf.substring(18,24); break;}       case 5: {sw=sw+rf.substring(24,30); break;}       case 6: {sw=sw+rf.substring(30,36); break;}       case 7: {sw=sw+rf.substring(36,42); break;}       case 8: {sw=sw+rf.substring(42,48); break;}      }//      System.out.println(sw);int a=0,b=0,c=0;    if((sw.charAt(0)=='0')&&(sw.charAt(5)=='0')) {a=0;}    if((sw.charAt(0)=='0')&&(sw.charAt(5)=='1')) {a=1;}    if((sw.charAt(0)=='1')&&(sw.charAt(5)=='0')) {a=2;}    if((sw.charAt(0)=='1')&&(sw.charAt(5)=='1')) {a=3;}    if(sw.charAt(1)=='1'){b=b+8;}    if(sw.charAt(2)=='1'){b=b+4;}    if(sw.charAt(3)=='1'){b=b+2;}    if(sw.charAt(4)=='1'){b=b+1;}//System.out.println("a="+a+" b="+b);    switch(z)    { case 1:{c=s1[a][b];break;}      case 2:{c=s2[a][b];break;}      case 3:{c=s3[a][b];break;}      case 4:{c=s4[a][b];break;}      case 5:{c=s5[a][b];break;}      case 6:{c=s6[a][b];break;}      case 7:{c=s7[a][b];break;}      case 8:{c=s8[a][b];break;}    }//System.out.println(n+": c="+c);    switch (c)    {    case  0:{rs=rs+"0000";break;}    case  1:{rs=rs+"0001";break;}    case  2:{rs=rs+"0010";break;}    case  3:{rs=rs+"0011";break;}    case  4:{rs=rs+"0100";break;}    case  5:{rs=rs+"0101";break;}    case  6:{rs=rs+"0110";break;}    case  7:{rs=rs+"0111";break;}    case  8:{rs=rs+"1000";break;}    case  9:{rs=rs+"1001";break;}    case 10:{rs=rs+"1010";break;}    case 11:{rs=rs+"1011";break;}    case 12:{rs=rs+"1100";break;}    case 13:{rs=rs+"1101";break;}    case 14:{rs=rs+"1110";break;}    case 15:{rs=rs+"1111";break;}    }//System.out.println("rs is "+rs);    }//System.out.println("rs is "+rs);   rs="0"+rs;   rp=rp+   rs.charAt(16)+rs.charAt(7)+rs.charAt(20)+rs.charAt(21)+rs.charAt(29)+rs.charAt(12)+rs.charAt(28)+rs.charAt(17)+   rs.charAt(1)+rs.charAt(15)+rs.charAt(23)+rs.charAt(26)+rs.charAt(5)+rs.charAt(18)+rs.charAt(31)+rs.charAt(10)+   rs.charAt(2)+rs.charAt(8)+rs.charAt(24)+rs.charAt(14)+rs.charAt(32)+rs.charAt(27)+rs.charAt(3)+rs.charAt(9)+   rs.charAt(19)+rs.charAt(13)+rs.charAt(30)+rs.charAt(6)+rs.charAt(22)+rs.charAt(11)+rs.charAt(4)+rs.charAt(25);//System.out.println("rp is "+rp);lj="";rj="";//System.out.println("rp is "+rp);//System.out.println("li"+li);       for(int p=1;p<=32;p++)       {if ((rp.charAt(p-1)=='0')&&(li.charAt(p)=='0'))        {rj=rj+"1";} else {rj=rj+"0";}   }//System.out.println("rj is "+rj);lj=ri.substring(0);rj="0"+rj;//System.out.println("lj is "+lj);//System.out.println("rj is "+rj);li=lj;ri=rj;//System.out.println("li is "+li);//System.out.println("ri is "+ri);}///16String out="";String outtext="";out=li.substring(1)+ri.substring(1);//System.out.println("out is "+out);out="0"+out;    outtext=outtext+    out.charAt(40)+out.charAt(8)+out.charAt(48)+out.charAt(16)+out.charAt(56)+out.charAt(24)+out.charAt(64)+out.charAt(32)+    out.charAt(39)+out.charAt(7)+out.charAt(47)+out.charAt(15)+out.charAt(55)+out.charAt(23)+out.charAt(63)+out.charAt(31)+    out.charAt(38)+out.charAt(6)+out.charAt(46)+out.charAt(14)+out.charAt(54)+out.charAt(22)+out.charAt(62)+out.charAt(30)+    out.charAt(37)+out.charAt(5)+out.charAt(45)+out.charAt(13)+out.charAt(53)+out.charAt(21)+out.charAt(61)+out.charAt(29)+    out.charAt(36)+out.charAt(4)+out.charAt(44)+out.charAt(12)+out.charAt(52)+out.charAt(20)+out.charAt(60)+out.charAt(28)+    out.charAt(35)+out.charAt(3)+out.charAt(43)+out.charAt(11)+out.charAt(51)+out.charAt(19)+out.charAt(59)+out.charAt(27)+    out.charAt(34)+out.charAt(2)+out.charAt(42)+out.charAt(10)+out.charAt(50)+out.charAt(18)+out.charAt(58)+out.charAt(26)+    out.charAt(33)+out.charAt(1)+out.charAt(41)+out.charAt(9)+out.charAt(49)+out.charAt(17)+out.charAt(57)+out.charAt(25);System.out.println("outtext is "+outtext);for(int n=1;n<=8;n++){String outword="";outword=outtext.substring(0,8);outtext=outtext.substring(8);//System.out.println(outword);//System.out.println(outtext);int word=0;//word=word+((int)outword.charAt(0))*128+((int)outword.charAt(1))*64+((int)outword.charAt(2))*32+((int)outword.charAt(3))*16+((int)outword.charAt(4))*8+((int)outword.charAt(5))*4+((int)outword.charAt(6))*2+((int)outword.charAt(7))*1;  if(outword.charAt(0)=='1') word=word+128;  if(outword.charAt(1)=='1') word=word+64;  if(outword.charAt(2)=='1') word=word+32;  if(outword.charAt(3)=='1') word=word+16;  if(outword.charAt(4)=='1') word=word+8;  if(outword.charAt(5)=='1') word=word+4;  if(outword.charAt(6)=='1') word=word+2;  if(outword.charAt(7)=='1') word=word+1;System.out.println(word);char ch;ch=((char)word);this.jTextArea2.setText(this.jTextArea2.getText()+ch);}///////////////////////////////////////////////////    }///8}  }class MainFrame_jTextField1_keyAdapter extends java.awt.event.KeyAdapter {  MainFrame adaptee;  MainFrame_jTextField1_keyAdapter(MainFrame adaptee) {    this.adaptee = adaptee;  }  public void keyPressed(KeyEvent e) {    adaptee.jTextField1_keyPressed(e);  }}class MainFrame_jButton1_actionAdapter implements java.awt.event.ActionListener {  MainFrame adaptee;  MainFrame_jButton1_actionAdapter(MainFrame adaptee) {    this.adaptee = adaptee;  }  public void actionPerformed(ActionEvent e) {    adaptee.jButton1_actionPerformed(e);  }}class MainFrame_jButton2_actionAdapter implements java.awt.event.ActionListener {  MainFrame adaptee;  MainFrame_jButton2_actionAdapter(MainFrame adaptee) {    this.adaptee = adaptee;  }  public void actionPerformed(ActionEvent e) {    adaptee.jButton2_actionPerformed(e);  }}class MainFrame_jButton3_actionAdapter implements java.awt.event.ActionListener {  MainFrame adaptee;  MainFrame_jButton3_actionAdapter(MainFrame adaptee) {    this.adaptee = adaptee;  }  public void actionPerformed(ActionEvent e) {    adaptee.jButton3_actionPerformed(e);  }}class MainFrame_jButton4_actionAdapter implements java.awt.event.ActionListener {  MainFrame adaptee;  MainFrame_jButton4_actionAdapter(MainFrame adaptee) {    this.adaptee = adaptee;  }  public void actionPerformed(ActionEvent e) {    adaptee.jButton4_actionPerformed(e);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -