[Java] IDEA加密工具 →→→→→进入此内容的聊天室

来自 , 2019-04-13, 写在 Java, 查看 111 次.
URL http://www.code666.cn/view/afda3322
  1. import com.ms.wfc.app.*;
  2. import com.ms.wfc.core.*;
  3. import com.ms.wfc.ui.*;
  4. import com.ms.wfc.html.*;
  5.  
  6. /**
  7.  * This class can take a variable number of parameters on the command
  8.  * line. Program execution begins with the main() method. The class
  9.  * constructor is not invoked unless an object of type 'FormIDEAwindow'
  10.  * created in the main() method.
  11.  */
  12. public class FormIDEAwindow extends Form
  13. {
  14.         public static int MtoCorCtoM;                                           //加密或脱密类型:0为加密
  15.        
  16.         public static final int TYPE_M_TO_C = 0;                        //代表加密的常量
  17.         public static final int TYPE_C_TO_M = 1;                        //代表脱密的常量
  18.        
  19.         public static final int maxim=65537;                            //常量2的16次方加1,即65537
  20.         public static final int fuyi=65536;                                     //常量2的16次方,即65536
  21.         public static final int one=65535;                                      //常量65535,即低16位为1的整型
  22.         public static final int round=8;
  23.        
  24.         int group;                                                                                      //正在进行的分组组数
  25.         Count16[] count16MorC;                                                          //16进制的明文或密文数组
  26.         String strCorM = new String("");                                        //16进制的明文或密文的字符串保存形式
  27.         char[][] Z = new char[7][10];                                           //加密密钥:Z[4][6]表示第6圈的第4个加密密钥
  28.         char[][] DK = new char[7][10];                                          //脱密密钥:DK[2][9]表示第9圈即输出变换圈的第2个脱密密钥
  29.         char[] XX = new char[5];                                                        //128比特的明文或密文表示形式
  30.         char[] userKey = new char[9];                                           //用户输入的128位初始密钥
  31.        
  32.         public FormIDEAwindow()
  33.         {
  34.                 super();
  35.  
  36.                 // Required for Visual J++ Form Designer support
  37.                 initForm();            
  38.  
  39.                 // TODO: Add any constructor code after initForm call
  40.         }
  41.  
  42.         /**
  43.          * FormIDEAwindow overrides dispose so it can clean up the
  44.          * component list.
  45.          */
  46.         public void dispose()
  47.         {
  48.                 super.dispose();
  49.                 components.dispose();
  50.         }
  51.  
  52.         private void menuItemIDEABegin_click(Object source, Event e)            //开始按钮
  53.         {
  54.                 if(menuItemIDEABegin.getText().equals("重来"))
  55.                 {
  56.                         super.dispose();
  57.                         components.dispose();
  58.                         Application.run(new FormIDEAwindow());
  59.                 }
  60.                 else
  61.                 {
  62.                         panelIDEA.setVisible(false);
  63.                         labelIDEAInstruction.setVisible(true);
  64.                         labelIDEAInputMorC.setVisible(true);
  65.                         labelIDEAMorClength.setVisible(true);
  66.                         richEditIDEAInputMorC.setVisible(true);
  67.                         labelIDEAInputK.setVisible(true);
  68.                         labelIDEAKlength.setVisible(true);
  69.                         richEditIDEAInputK.setVisible(true);
  70.                         labelIDEACheckInputMorC.setVisible(true);
  71.                         labelIDEACheckInputK.setVisible(true); 
  72.                         buttonIDEACalculate.setVisible(true);
  73.                         labelIDEAKResult.setVisible(true);
  74.                         richEditIDEAKResult.setVisible(true);
  75.                         labelIDEAResult.setVisible(true);
  76.                         richEditIDEAResult.setVisible(true);
  77.                         menuItemIDEABegin.setText("重来");
  78.                         if(MtoCorCtoM == TYPE_M_TO_C)
  79.                         {
  80.                                 labelIDEADataFillType.setVisible(true);
  81.                                 labelIDEAChangeDataFillType.setVisible(true);
  82.                                 buttonIDEAChangeDataFillType.setVisible(true);
  83.                                 labelIDEAInstruction.setText("这个程序用来进行IDEA分组密码算法的加密运算");
  84.                                 labelIDEAInputMorC.setText("请输入初始明文");
  85.                                 labelIDEAInputK.setText("请输入用户密钥");
  86.                                 buttonIDEACalculate.setText("加密");
  87.                                 labelIDEAKResult.setText("生成密钥");
  88.                                 labelIDEAResult.setText("生成密文:");
  89.                         }
  90.                         else
  91.                         {
  92.                                 labelIDEAInstruction.setText("这个程序用来进行IDEA分组密码算法的脱密运算");
  93.                                 labelIDEAInputMorC.setText("请输入初始密文");
  94.                                 labelIDEAInputK.setText("请输入用户密钥");
  95.                                 buttonIDEACalculate.setText("脱密");
  96.                                 labelIDEAKResult.setText("生成密钥");
  97.                                 labelIDEAResult.setText("生成明文:");
  98.                         }
  99.                 }
  100.         }
  101.  
  102.         private void menuItemIDEABack_click(Object source, Event e)                     //返回按钮
  103.         {
  104.                 super.dispose();
  105.                 components.dispose();
  106.                 Application.run(new Form1());
  107.         }
  108.  
  109.         private void menuItemIDEAExit_click(Object source, Event e)                     //退出按钮
  110.         {
  111.                 int result = MessageBox.show("感谢使用本软件。\n你真的要退出本程序吗?","密码学算法软件",MessageBox.OKCANCEL+MessageBox.ICONQUESTION+MessageBox.DEFBUTTON1);
  112.                 if(result==DialogResult.OK)
  113.                 {
  114.                         super.dispose();
  115.                         components.dispose();
  116.                         Application.exit();
  117.                 }
  118.                 else
  119.                 {
  120.                 }
  121.         }
  122.  
  123.         private void richEditIDEAInputMorC_textChanged(Object source, Event e)                          //显示输入明密文长度
  124.         {
  125.                 labelIDEAMorClength.setText("长度:"+richEditIDEAInputMorC.getText().length()+",即"+richEditIDEAInputMorC.getText().length()*4+"bit");
  126.         }
  127.  
  128.         private void richEditIDEAInputK_textChanged(Object source, Event e)                                     //显示输入密钥长度
  129.         {
  130.                 labelIDEAKlength.setText("长度:"+richEditIDEAInputK.getText().length()+",即"+richEditIDEAInputK.getText().length()*4+"bit");
  131.         }
  132.  
  133.         private void buttonIDEAChangeDataFillType_click(Object source, Event e)                         //加密时需改变数据填充类型
  134.         {
  135.                 comboBoxIDEAChangeDataFillType.setVisible(true);
  136.                 buttonIDEAChangeDataFillType.setVisible(false);
  137.                 buttonIDEACalculate.setEnabled(false);
  138.         }
  139.  
  140.         private void comboBoxIDEAChangeDataFillType_selectedIndexChanged(Object source, Event e)
  141.         {
  142.                 if((String)comboBoxIDEAChangeDataFillType.getSelectedItem() != null)                    //选择填充方式
  143.                 {
  144.                         buttonIDEACalculate.setEnabled(true);
  145.                 }      
  146.         }
  147.  
  148.         private void key(char[] usekey)                                                                 //生成加密密钥
  149.         {
  150.                 if(usekey.length==9)
  151.                 {
  152.                         char[] S = new char[52];
  153.                         int i,j,r;
  154.                        
  155.                         for(i=1;i<9;i++)                                                                                //S[1],S[2],……S[8]
  156.                         {
  157.                                 S[i-1]=usekey[i];
  158.                         }
  159.                         for(i=8;i<52;i++)
  160.                         {
  161.                                 if((i+2)%8==0)                                                                          //S[14],S[22],……
  162.                                 {
  163.                                         S[i]=(char)(((int)((char)((int)S[i-7]<<9))^(int)((char)((int)S[i-14]>>7)))&one);
  164.                                 }
  165.                                 else
  166.                                 {
  167.                                         if((i+1)%8==0)                                                                  //S[15],S[23],……
  168.                                         {
  169.                                                 S[i]=(char)(((int)((char)((int)S[i-15]<<9))^(int)((char)((int)S[i-14]>>7)))&one);
  170.                                         }                                      
  171.                                         else
  172.                                         {
  173.                                                 S[i]=(char)(((int)((char)((int)S[i-7]<<9))^(int)((char)((int)S[i-6]>>7)))&one);
  174.                                         }
  175.                                 }
  176.                         }
  177.                         for(r=1;r<=round;r++)                                                                   //形成加密密钥Z
  178.                         {
  179.                                 for(j=1;j<=6;j++)
  180.                                 {      
  181.                                         Z[j][r]=S[6*(r-1)+j-1];
  182.                                 }
  183.                         }
  184.                         if(r==round+1)
  185.                         {
  186.                                 for(j=1;j<=4;j++)
  187.                                 {
  188.                                         Z[j][r]=S[6*(r-1)+j-1];
  189.                                 }
  190.                         }
  191.                 }
  192.         }
  193.        
  194.         private void de_key(char[][] Zkey)                                                              //生成脱密密钥DK
  195.         {
  196.                 if(Zkey.length==7&Zkey[0].length==10)
  197.                 {
  198.                         int i,j;
  199.                        
  200.                         for(j=1;j<=round+1;j++)
  201.                         {
  202.                                 DK[1][round-j+2]=(char)Maths.inverse((int)Zkey[1][j],maxim);
  203.                                 DK[4][round-j+2]=(char)Maths.inverse((int)Zkey[4][j],maxim);
  204.                                 if(j==1||j==round+1)
  205.                                 {
  206.                                         DK[2][round-j+2]=(char)((fuyi-(int)Zkey[2][j])&one);
  207.                                         DK[3][round-j+2]=(char)((fuyi-(int)Zkey[3][j])&one);
  208.                                 }
  209.                                 else
  210.                                 {
  211.                                         DK[2][round-j+2]=(char)((fuyi-(int)Zkey[3][j])&one);
  212.                                         DK[3][round-j+2]=(char)((fuyi-(int)Zkey[2][j])&one);
  213.                                 }
  214.                         }
  215.                         for(j=1;j<=round+1;j++)
  216.                         {
  217.                                 DK[5][round+1-j]=Zkey[5][j];
  218.                                 DK[6][round+1-j]=Zkey[6][j];
  219.                         }
  220.                 }
  221.         }
  222.        
  223.         private void keyPrint(char[][] Key)                                                             //加脱密密钥打印
  224.         {
  225.                 int i,j,k;
  226.                 String strK;
  227.                 Count16[] count16print = new Count16[4];
  228.                 for(i=0; i<4; i++)
  229.                 {
  230.                         count16print[i] = new Count16();
  231.                 }
  232.                
  233.                 strK = "     ";
  234.                 for(i=1; i<7; i++)
  235.                 {
  236.                         if(MtoCorCtoM==TYPE_M_TO_C)
  237.                         {
  238.                                 strK = strK+"   Z"+i+" ";
  239.                         }
  240.                         else
  241.                         {
  242.                                 strK = strK+"   U"+i+" ";
  243.                         }
  244.                 }
  245.                 for(i=1; i<9; i++)
  246.                 {
  247.                         strK = strK+"第"+i+"圈: ";
  248.                         for(j=1; j<7; j++)
  249.                         {
  250.                                 count16print = Count16.shortToCount16(Key[j][i]);
  251.                                 for(k=0; k<4; k++)
  252.                                 {
  253.                                         strK = strK+count16print[k].gethex();
  254.                                 }
  255.                                 if(j<6)
  256.                                 {
  257.                                         strK = strK+"  ";
  258.                                 }
  259.                         }
  260.                 }
  261.                 strK = strK+"第"+i+"圈: ";
  262.                 for(j=1; j<5; j++)
  263.                 {
  264.                         count16print = Count16.shortToCount16(Key[j][i]);
  265.                         for(k=0; k<4; k++)
  266.                         {
  267.                                 strK = strK+count16print[k].gethex();
  268.                         }
  269.                         if(j<4)
  270.                         {
  271.                                 strK = strK+"  ";
  272.                         }
  273.                 }
  274.                
  275.                 richEditIDEAKResult.setText(strK);
  276.         }
  277.                        
  278.         private void buttonIDEACalculate_click(Object source, Event e)          //加密或脱密计算按钮
  279.         {
  280.                 int col,row;
  281.                 boolean rightInput = false;
  282.                 String strMorC;
  283.                 String strK;
  284.                 strMorC = richEditIDEAInputMorC.getText();
  285.                 strK = richEditIDEAInputK.getText();
  286.                 if(strMorC.equals("")|strK.equals(""))                                                  //明密文或密钥为空
  287.                 {
  288.                 }
  289.                 else
  290.                 {
  291.                         char[] chMorC = new char[strMorC.length()];
  292.                         char[] chK = new char[strK.length()];
  293.                         chMorC = strMorC.toCharArray();
  294.                         chK = strK.toCharArray();
  295.                        
  296.                         for(col=0; col<chMorC.length; col++)
  297.                         {
  298.                                 if(chMorC[col]< '0'|(chMorC[col]> '9'&chMorC[col]< 'A')|chMorC[col]> 'F')       //检测输入合法性
  299.                                 {
  300.                                         if(MtoCorCtoM == TYPE_M_TO_C)
  301.                                         {
  302.                                                 if(chMorC[col]==' ')
  303.                                                 {
  304.                                                         labelIDEACheckInputMorC.setText("明文中第"+(col+1)+"位字符是空格,请删除");
  305.                                                 }
  306.                                                 else
  307.                                                 {
  308.                                                         labelIDEACheckInputMorC.setText("明文中第"+(col+1)+"位字符不合法");
  309.                                                 }
  310.                                         }
  311.                                         else
  312.                                         {
  313.                                                 if(chMorC[col]==' ')
  314.                                                 {
  315.                                                         labelIDEACheckInputMorC.setText("密文中第"+(col+1)+"位字符是空格,请删除");
  316.                                                 }
  317.                                                 else
  318.                                                 {
  319.                                                         labelIDEACheckInputMorC.setText("密文中第"+(col+1)+"位字符不合法");
  320.                                                 }
  321.                                         }
  322.                                         rightInput = false;
  323.                                         break;
  324.                                 }
  325.                         }
  326.                         if(col==chMorC.length)
  327.                         {
  328.                                 labelIDEACheckInputMorC.setText("");
  329.                         }
  330.                         for(row=0; row<chK.length; row++)
  331.                         {
  332.                                 if(chK[row]< '0'|(chK[row]> '9'&chK[row]< 'A')|chK[row]> 'F')
  333.                                 {
  334.                                         if(chK[row]==' ')
  335.                                         {
  336.                                                 labelIDEACheckInputK.setText("密钥中第"+(row+1)+"位字符是空格,请删除");
  337.                                         }
  338.                                         else
  339.                                         {
  340.                                                 labelIDEACheckInputK.setText("密钥中第"+(row+1)+"位字符不合法");
  341.                                         }
  342.                                         rightInput = false;
  343.                                         break;
  344.                                 }
  345.                         }
  346.                         if(row==chK.length)
  347.                         {
  348.                                 labelIDEACheckInputK.setText("");
  349.                         }
  350.                         if(col==chMorC.length & row==chK.length)
  351.                         {
  352.                                 rightInput = true;
  353.                         }
  354.                         if(chK.length!=32)                                                                                                              //长度检测
  355.                         {
  356.                                 labelIDEACheckInputK.setText("密钥长度必须为128bit,即32个字符");
  357.                                 rightInput = false;
  358.                         }
  359.                         if(MtoCorCtoM==TYPE_C_TO_M && chMorC.length%16!=0)
  360.                         {
  361.                                 labelIDEACheckInputMorC.setText("密文长度必须为64bit的整数倍");
  362.                                 rightInput = false;
  363.                         }
  364.                         if(rightInput==true)                                                                                                    //检测输入正确时
  365.                         {
  366.                                 labelIDEACheckInputMorC.setText("");
  367.                                 labelIDEACheckInputK.setText("");
  368.                                
  369.                                 Count16[] count16temp = new Count16[4];
  370.                                 for(col=0; col<4; col++)
  371.                                 {
  372.                                         count16temp[col] = new Count16();
  373.                                 }
  374.                                
  375.                                 for(col=0; col<32; col=col+4)
  376.                                 {
  377.                                         for(row=0; row<4; row++)
  378.                                         {
  379.                                                 count16temp[row].sethex(chK[col+row]);
  380.                                         }                                      
  381.                                         userKey[col/4+1] = Count16.toshort(count16temp);                                //生成用户密钥
  382.                                 }
  383.                                 key(userKey);                                                                                                           //生成密钥
  384.                                 if(MtoCorCtoM==TYPE_C_TO_M)                                                                                     //生成脱密密钥并打印
  385.                                 {
  386.                                         de_key(Z);
  387.                                         keyPrint(DK);
  388.                                 }
  389.                                 else                                                                                                                            //打印加密密钥
  390.                                 {
  391.                                         keyPrint(Z);
  392.                                 }
  393.                                
  394.                                 count16MorC = new Count16[((chMorC.length-1)/16+1)*16];                         //明密文存储内存分配
  395.                                 for(col=0; col<count16MorC.length; col++)
  396.                                 {
  397.                                         count16MorC[col] = new Count16();
  398.                                 }
  399.                                 for(col=0; col<chMorC.length; col++)
  400.                                 {
  401.                                         count16MorC[col].sethex(chMorC[col]);
  402.                                 }
  403.                                                                        
  404.                                 if(MtoCorCtoM==TYPE_M_TO_C && buttonIDEAChangeDataFillType.getVisible()==false)
  405.                                 {
  406.                                         for(col=chMorC.length; col<count16MorC.length; col++)                   //默认填充0
  407.                                         {
  408.                                                 count16MorC[col].sethex('0');
  409.                                         }
  410.                                        
  411.                                         String strDataFillType;
  412.                                         strDataFillType = (String)comboBoxIDEAChangeDataFillType.getSelectedItem();
  413.                                         if(strDataFillType.equals("填充 0 (默认)"))
  414.                                         {
  415.                                         }
  416.                                         if(strDataFillType.equals("填充 1"))                                                  //填充1
  417.                                         {
  418.                                                 for(col=chMorC.length; col<count16MorC.length; col++)
  419.                                                 {
  420.                                                         count16MorC[col].sethex('F');
  421.                                                 }
  422.                                         }
  423.                                         if(strDataFillType.equals("填充0和1(先0后1)"))                                     //填充01
  424.                                         {
  425.                                                 for(col=chMorC.length; col<count16MorC.length; col++)
  426.                                                 {
  427.                                                         count16MorC[col].sethex('5');
  428.                                                 }
  429.                                         }
  430.                                         if(strDataFillType.equals("填充1和0(先1后0)"))                                     //填充10
  431.                                         {
  432.                                                 for(col=chMorC.length; col<count16MorC.length; col++)
  433.                                                 {
  434.                                                         count16MorC[col].sethex('A');
  435.                                                 }
  436.                                         }                                      
  437.                                 }
  438.                                
  439.                                 for(group=1; group<=(count16MorC.length/16); group++)                           //分组信息
  440.                                 {
  441.                                         for(col=(group-1)*16,row=0; row<16; col++,row++)
  442.                                         {
  443.                                                 count16temp[row%4].sethex(count16MorC[col].gethex());
  444.                                                 if(row%4==3)
  445.                                                 {
  446.                                                         XX[row/4+1] = Count16.toshort(count16temp);
  447.                                                 }
  448.                                         }
  449.                                        
  450.                                         if(MtoCorCtoM == TYPE_M_TO_C)                                                                   //加密计算
  451.                                         {
  452.                                                 cip(XX,Z);
  453.                                         }
  454.                                         else                                                                                                                    //脱密计算
  455.                                         {
  456.                                                 cip(XX,DK);
  457.                                         }                                      
  458.                                 }
  459.                                
  460.                                 richEditIDEAResult.setText(strCorM);
  461.                                 strCorM = "";
  462.                                
  463.                                 buttonIDEACalculate.setEnabled(false);
  464.                                 richEditIDEAInputK.setEnabled(false);
  465.                                 richEditIDEAInputMorC.setEnabled(false);
  466.                                 richEditIDEAInputK.setBackColor(Color.LIGHTGRAY);
  467.                                 richEditIDEAInputMorC.setBackColor(Color.LIGHTGRAY);
  468.                                 buttonIDEAChangeDataFillType.setEnabled(false);
  469.                                 comboBoxIDEAChangeDataFillType.setEnabled(false);
  470.                                 comboBoxIDEAChangeDataFillType.setBackColor(Color.LIGHTGRAY);
  471.                         }
  472.                 }
  473.         }
  474.        
  475.         private void cip(char[] IN,char[][] KEY)                                                                                //加密函数 
  476.         {
  477.                 int i,j,r;
  478.                 char[] OUT = new char[5];
  479.                 char[] x = new char[5];
  480.                 char kk,t1,t2,a;
  481.                 Count16[] roundOut = new Count16[4];
  482.                 for(i=0; i<4; i++)
  483.                 {
  484.                         roundOut[i] = new Count16();
  485.                 }
  486.                
  487.                 strCorM = strCorM + "*****************************************";
  488.                 if(MtoCorCtoM == TYPE_M_TO_C)
  489.                 {
  490.                         strCorM = strCorM + "第"+group+"组密文:                               ";
  491.                 }
  492.                 else
  493.                 {
  494.                         strCorM = strCorM + "第"+group+"组明文:                               ";
  495.                 }
  496.                 strCorM = strCorM + "-----------------------------------------";
  497.                 x[1]=IN[1];
  498.                 x[2]=IN[2];
  499.                 x[3]=IN[3];
  500.                 x[4]=IN[4];
  501.                
  502.                 for(r=1;r<=8;r++)                                                                                                                       //8圈迭代.
  503.                 {
  504.                         x[1]=mul(x[1],KEY[1][r]);
  505.                         x[2]=(char)(((int)x[2]+(int)KEY[2][r])&one);
  506.                         x[3]=(char)(((int)x[3]+(int)KEY[3][r])&one);
  507.                         x[4]=mul(x[4],KEY[4][r]);
  508.                                                                                                                                                                         //乘加(MA)结构.
  509.                         kk=mul(KEY[5][r],(char)((int)x[1]^(int)x[3]));
  510.                         t1=mul(KEY[6][r],(char)(((int)kk+((int)x[2]^(int)x[4]))&one));
  511.                         t2=(char)(((int)kk+(int)t1)&one);
  512.                                                                                                                                                                         //下一圈输入交换.
  513.                         x[1]=(char)((int)x[1]^(int)t1);
  514.                         x[4]=(char)((int)x[4]^(int)t2);
  515.                         a=(char)((int)x[2]^(int)t2);
  516.                         x[2]=(char)((int)x[3]^(int)t1);
  517.                         x[3]=a;
  518.                        
  519.                         strCorM = strCorM+"第"+r+"圈输出:       ";
  520.                         for(i=1; i<5; i++)
  521.                         {
  522.                                 roundOut = Count16.shortToCount16( x[i] );
  523.                                 for(j=0; j<4; j++)
  524.                                 {
  525.                                         strCorM = strCorM + roundOut[j].gethex();
  526.                                 }
  527.                                 strCorM = strCorM + "  ";
  528.                         }
  529.                 }
  530.                                                                                                                                                                         //输出变换得出加脱密结果.
  531.                 OUT[1]=mul(x[1],KEY[1][round+1]);
  532.                 OUT[4]=mul(x[4],KEY[4][round+1]);
  533.                 OUT[2]=(char)((x[3]+KEY[2][round+1])&one);
  534.                 OUT[3]=(char)((x[2]+KEY[3][round+1])&one);
  535.                
  536.                 if(MtoCorCtoM == TYPE_M_TO_C)                                                                                           //为打印作准备
  537.                 {
  538.                         if(group<=9)
  539.                         {
  540.                                 strCorM = strCorM+"第"+group+"组加密结果:   ";
  541.                         }
  542.                         else
  543.                         {
  544.                                 strCorM = strCorM+"第"+group+"组加密结果:  ";
  545.                         }
  546.                 }
  547.                 else
  548.                 {
  549.                         if(group<=9)
  550.                         {
  551.                                 strCorM = strCorM+"第"+group+"组脱密结果:   ";
  552.                         }
  553.                         else
  554.                         {
  555.                                 strCorM = strCorM+"第"+group+"组脱密结果:  ";
  556.                         }
  557.                 }
  558.                 for(i=1; i<5; i++)
  559.                 {
  560.                         roundOut = Count16.shortToCount16( OUT[i] );
  561.                         for(j=0; j<4; j++)
  562.                         {
  563.                                 strCorM = strCorM + roundOut[j].gethex();
  564.                         }
  565.                         strCorM = strCorM + "  ";
  566.                 }
  567.                 strCorM = strCorM+"*****************************************";
  568.         }
  569.        
  570.         private char mul(char a,char b)                                                                                                 //模2的16次方加1运算
  571.         {
  572.                 int p;
  573.                 long q;
  574.                 if((int)a==0)
  575.                 {
  576.                         p=maxim-(int)b;
  577.                 }
  578.                 else
  579.                 {
  580.                         if((int)b==0)
  581.                         {
  582.                                 p=maxim-(int)a;
  583.                         }
  584.                         else
  585.                         {
  586.                                 q=(long)a*(long)b;
  587.                                 if((q&((long)one))>(long)(q>>16))
  588.                                 {
  589.                                         p=(int)((q&((long)one))-(long)(q>>16));
  590.                                 }
  591.                                 else
  592.                                 {
  593.                                         p=(int)((q&((long)one))+(long)maxim-(long)(q>>16));
  594.                                 }
  595.                         }
  596.                 }
  597.                 return (char)(p&one);
  598.         }      
  599.        
  600.         private void menuItemHelp_click(Object source, Event e)
  601.         {
  602.                 MessageBox.show("IDEA算法使用帮助:\n  输入框内可以输入字符\n0-9以及大字字母A-F,注意小写字母不行。\n如果输入的字符不能通过检查,请确认是否输入了回车键。\n如有,请将回车字符删去。\n\n说明:\n  剪切: Ctrl+X\n  复制: Ctrl+C\n  粘贴: Ctrl+V"
  603.                                                 ,"请注意",MessageBox.OK+MessageBox.ICONEXCLAMATION+MessageBox.DEFBUTTON1);
  604.         }
  605.  
  606.         /**
  607.          * NOTE: The following code is required by the Visual J++ form
  608.          * designer.  It can be modified using the form editor.  Do not
  609.          * modify it using the code editor.
  610.          */
  611.         Container components = new Container();
  612.         MainMenu mainMenuIDEA = new MainMenu();
  613.         MenuItem menuItemIDEABegin = new MenuItem();
  614.         MenuItem menuItemIDEABack = new MenuItem();
  615.         MenuItem menuItemIDEAExit = new MenuItem();
  616.         Label labelIDEAInstruction = new Label();
  617.         RichEdit richEditIDEAResult = new RichEdit();
  618.         Button buttonIDEACalculate = new Button();
  619.         Label labelIDEACheckInputMorC = new Label();
  620.         ComboBox comboBoxIDEAChangeDataFillType = new ComboBox();
  621.         Button buttonIDEAChangeDataFillType = new Button();
  622.         Label labelIDEAChangeDataFillType = new Label();
  623.         Label labelIDEAInputMorC = new Label();
  624.         Label labelIDEADataFillType = new Label();
  625.         RichEdit richEditIDEAInputK = new RichEdit();
  626.         Label labelIDEAKlength = new Label();
  627.         Label labelIDEAMorClength = new Label();
  628.         RichEdit richEditIDEAInputMorC = new RichEdit();
  629.         Label labelIDEAInputK = new Label();
  630.         Label labelIDEACheckInputK = new Label();
  631.         RichEdit richEditIDEAKResult = new RichEdit();
  632.         Label labelIDEAKResult = new Label();
  633.         Label labelIDEAResult = new Label();
  634.         MenuItem menuItemHelp = new MenuItem();
  635.         Panel panelIDEA = new Panel();
  636.         PictureBox pictureBoxIDEA = new PictureBox();
  637.         RichEdit richEditBegin = new RichEdit();
  638.         RichEdit richEditzhuyi = new RichEdit();
  639.  
  640.         private void initForm()
  641.         {
  642.                 // NOTE:  This form is storing resource information in an
  643.                 // external file.  Do not modify the string parameter to any
  644.                 // resources.getObject() function call. For example, do not
  645.                 // modify "foo1_location" in the following line of code
  646.                 // even if the name of the Foo object changes:
  647.                 //   foo1.setLocation((Point)resources.getObject("foo1_location"));
  648.  
  649.                 IResourceManager resources = new ResourceManager(this, "FormIDEAwindow");
  650.                 menuItemIDEABegin.setText("开始");
  651.                 menuItemIDEABegin.addOnClick(new EventHandler(this.menuItemIDEABegin_click));
  652.  
  653.                 menuItemIDEABack.setText("返回");
  654.                 menuItemIDEABack.addOnClick(new EventHandler(this.menuItemIDEABack_click));
  655.  
  656.                 menuItemIDEAExit.setText("退出");
  657.                 menuItemIDEAExit.addOnClick(new EventHandler(this.menuItemIDEAExit_click));
  658.  
  659.                 labelIDEAInstruction.setFont(new Font("宋体", 16.0f, FontSize.POINTS, FontWeight.BOLD, false, false, false, CharacterSet.DEFAULT, 0));
  660.                 labelIDEAInstruction.setForeColor(Color.BLACK);
  661.                 labelIDEAInstruction.setLocation(new Point(32, 16));
  662.                 labelIDEAInstruction.setSize(new Point(288, 48));
  663.                 labelIDEAInstruction.setTabIndex(0);
  664.                 labelIDEAInstruction.setTabStop(false);
  665.                 labelIDEAInstruction.setText("");
  666.                 labelIDEAInstruction.setVisible(false);
  667.  
  668.                 richEditIDEAResult.setBackColor(new Color(204, 255, 51));
  669.                 richEditIDEAResult.setFont(new Font("宋体", 14.0f, FontSize.POINTS, FontWeight.NORMAL, false, false, false, CharacterSet.DEFAULT, 0));
  670.                 richEditIDEAResult.setForeColor(Color.WINDOWTEXT);
  671.                 richEditIDEAResult.setLocation(new Point(376, 184));
  672.                 richEditIDEAResult.setSize(new Point(400, 328));
  673.                 richEditIDEAResult.setTabIndex(13);
  674.                 richEditIDEAResult.setText("");
  675.                 richEditIDEAResult.setVisible(false);
  676.                 richEditIDEAResult.setReadOnly(true);
  677.                 richEditIDEAResult.setScrollBars(RichEditScrollBars.FORCED_VERTICAL);
  678.  
  679.                 buttonIDEACalculate.setFont(new Font("宋体", 18.0f, FontSize.POINTS, FontWeight.BOLD, false, false, false, CharacterSet.DEFAULT, 0));
  680.                 buttonIDEACalculate.setLocation(new Point(272, 392));
  681.                 buttonIDEACalculate.setSize(new Point(64, 48));
  682.                 buttonIDEACalculate.setTabIndex(12);
  683.                 buttonIDEACalculate.setText("");
  684.                 buttonIDEACalculate.setVisible(false);
  685.                 buttonIDEACalculate.addOnClick(new EventHandler(this.buttonIDEACalculate_click));
  686.  
  687.                 labelIDEACheckInputMorC.setBackColor(new Color(153, 77, 0));
  688.                 labelIDEACheckInputMorC.setFont(new Font("宋体", 14.0f, FontSize.POINTS, FontWeight.BOLD, false, false, false, CharacterSet.DEFAULT, 0));
  689.                 labelIDEACheckInputMorC.setForeColor(Color.BLACK);
  690.                 labelIDEACheckInputMorC.setLocation(new Point(16, 336));
  691.                 labelIDEACheckInputMorC.setSize(new Point(320, 20));
  692.                 labelIDEACheckInputMorC.setTabIndex(11);
  693.                 labelIDEACheckInputMorC.setTabStop(false);
  694.                 labelIDEACheckInputMorC.setText("");
  695.                 labelIDEACheckInputMorC.setVisible(false);
  696.                 labelIDEACheckInputMorC.setTextAlign(HorizontalAlignment.CENTER);
  697.  
  698.                 comboBoxIDEAChangeDataFillType.setBackColor(new Color(204, 255, 51));
  699.                 comboBoxIDEAChangeDataFillType.setFont(new Font("宋体", 9.0f, FontSize.POINTS, FontWeight.NORMAL, false, false, false, CharacterSet.DEFAULT, 0));
  700.                 comboBoxIDEAChangeDataFillType.setLocation(new Point(16, 472));
  701.                 comboBoxIDEAChangeDataFillType.setSize(new Point(192, 20));
  702.                 comboBoxIDEAChangeDataFillType.setTabIndex(10);
  703.                 comboBoxIDEAChangeDataFillType.setText("");
  704.                 comboBoxIDEAChangeDataFillType.setVisible(false);
  705.                 comboBoxIDEAChangeDataFillType.setStyle(ComboBoxStyle.DROPDOWNLIST);
  706.                 comboBoxIDEAChangeDataFillType.setItems(new Object[] {
  707.                                                                                                 "填充 0 (默认)",
  708.                                                                                                 "填充 1",
  709.                                                                                                 "填充0和1(先0后1)",
  710.                                                                                                 "填充1和0(先1后0)"});
  711.                 comboBoxIDEAChangeDataFillType.addOnSelectedIndexChanged(new EventHandler(this.comboBoxIDEAChangeDataFillType_selectedIndexChanged));
  712.  
  713.                 buttonIDEAChangeDataFillType.setFont(new Font("宋体", 9.0f, FontSize.POINTS, FontWeight.NORMAL, false, false, false, CharacterSet.DEFAULT, 0));
  714.                 buttonIDEAChangeDataFillType.setLocation(new Point(216, 448));
  715.                 buttonIDEAChangeDataFillType.setSize(new Point(32, 24));
  716.                 buttonIDEAChangeDataFillType.setTabIndex(9);
  717.                 buttonIDEAChangeDataFillType.setText("更改");
  718.                 buttonIDEAChangeDataFillType.setVisible(false);
  719.                 buttonIDEAChangeDataFillType.addOnClick(new EventHandler(this.buttonIDEAChangeDataFillType_click));
  720.  
  721.                 labelIDEAChangeDataFillType.setFont(new Font("宋体", 12.0f, FontSize.POINTS, FontWeight.NORMAL, true, false, false, CharacterSet.DEFAULT, 0));
  722.                 labelIDEAChangeDataFillType.setForeColor(new Color(224, 224, 224));
  723.                 labelIDEAChangeDataFillType.setLocation(new Point(16, 448));
  724.                 labelIDEAChangeDataFillType.setSize(new Point(192, 16));
  725.                 labelIDEAChangeDataFillType.setTabIndex(8);
  726.                 labelIDEAChangeDataFillType.setTabStop(false);
  727.                 labelIDEAChangeDataFillType.setText("改变默认的数据填充类型");
  728.                 labelIDEAChangeDataFillType.setVisible(false);
  729.                 labelIDEAChangeDataFillType.setTextAlign(HorizontalAlignment.CENTER);
  730.  
  731.                 labelIDEAInputMorC.setFont(new Font("宋体", 12.0f, FontSize.POINTS, FontWeight.BOLD, false, false, false, CharacterSet.DEFAULT, 0));
  732.                 labelIDEAInputMorC.setForeColor(Color.BLACK);
  733.                 labelIDEAInputMorC.setLocation(new Point(8, 88));
  734.                 labelIDEAInputMorC.setSize(new Point(152, 23));
  735.                 labelIDEAInputMorC.setTabIndex(1);
  736.                 labelIDEAInputMorC.setTabStop(false);
  737.                 labelIDEAInputMorC.setText("");
  738.                 labelIDEAInputMorC.setVisible(false);
  739.  
  740.                 labelIDEADataFillType.setFont(new Font("宋体", 12.0f, FontSize.POINTS, FontWeight.NORMAL, true, false, false, CharacterSet.DEFAULT, 0));
  741.                 labelIDEADataFillType.setForeColor(new Color(224, 224, 224));
  742.                 labelIDEADataFillType.setLocation(new Point(16, 424));
  743.                 labelIDEADataFillType.setSize(new Point(248, 16));
  744.                 labelIDEADataFillType.setTabIndex(7);
  745.                 labelIDEADataFillType.setTabStop(false);
  746.                 labelIDEADataFillType.setText("数据填充类型:填充 0 (默认)");
  747.                 labelIDEADataFillType.setVisible(false);
  748.                 labelIDEADataFillType.setTextAlign(HorizontalAlignment.CENTER);
  749.  
  750.                 richEditIDEAInputK.setBackColor(new Color(204, 255, 51));
  751.                 richEditIDEAInputK.setFont(new Font("宋体", 14.0f, FontSize.POINTS, FontWeight.NORMAL, false, false, false, CharacterSet.DEFAULT, 0));
  752.                 richEditIDEAInputK.setForeColor(Color.WINDOWTEXT);
  753.                 richEditIDEAInputK.setLocation(new Point(8, 248));
  754.                 richEditIDEAInputK.setSize(new Point(328, 80));
  755.                 richEditIDEAInputK.setTabIndex(6);
  756.                 richEditIDEAInputK.setText("");
  757.                 richEditIDEAInputK.setVisible(false);
  758.                 richEditIDEAInputK.setScrollBars(RichEditScrollBars.VERTICAL);
  759.                 richEditIDEAInputK.addOnTextChanged(new EventHandler(this.richEditIDEAInputK_textChanged));
  760.  
  761.                 labelIDEAKlength.setFont(new Font("宋体", 12.0f, FontSize.POINTS, FontWeight.BOLD, false, false, false, CharacterSet.DEFAULT, 0));
  762.                 labelIDEAKlength.setForeColor(Color.BLACK);
  763.                 labelIDEAKlength.setLocation(new Point(168, 216));
  764.                 labelIDEAKlength.setSize(new Point(192, 23));
  765.                 labelIDEAKlength.setTabIndex(5);
  766.                 labelIDEAKlength.setTabStop(false);
  767.                 labelIDEAKlength.setText("");
  768.  
  769.                 labelIDEAMorClength.setFont(new Font("宋体", 12.0f, FontSize.POINTS, FontWeight.BOLD, false, false, false, CharacterSet.DEFAULT, 0));
  770.                 labelIDEAMorClength.setForeColor(Color.BLACK);
  771.                 labelIDEAMorClength.setLocation(new Point(168, 88));
  772.                 labelIDEAMorClength.setSize(new Point(192, 23));
  773.                 labelIDEAMorClength.setTabIndex(4);
  774.                 labelIDEAMorClength.setTabStop(false);
  775.                 labelIDEAMorClength.setText("");
  776.  
  777.                 richEditIDEAInputMorC.setBackColor(new Color(204, 255, 51));
  778.                 richEditIDEAInputMorC.setFont(new Font("宋体", 14.0f, FontSize.POINTS, FontWeight.NORMAL, false, false, false, CharacterSet.DEFAULT, 0));
  779.                 richEditIDEAInputMorC.setForeColor(Color.WINDOWTEXT);
  780.                 richEditIDEAInputMorC.setLocation(new Point(8, 120));
  781.                 richEditIDEAInputMorC.setSize(new Point(328, 80));
  782.                 richEditIDEAInputMorC.setTabIndex(3);
  783.                 richEditIDEAInputMorC.setText("");
  784.                 richEditIDEAInputMorC.setVisible(false);
  785.                 richEditIDEAInputMorC.setScrollBars(RichEditScrollBars.VERTICAL);
  786.                 richEditIDEAInputMorC.addOnTextChanged(new EventHandler(this.richEditIDEAInputMorC_textChanged));
  787.  
  788.                 labelIDEAInputK.setFont(new Font("宋体", 12.0f, FontSize.POINTS, FontWeight.BOLD, false, false, false, CharacterSet.DEFAULT, 0));
  789.                 labelIDEAInputK.setForeColor(Color.BLACK);
  790.                 labelIDEAInputK.setLocation(new Point(8, 216));
  791.                 labelIDEAInputK.setSize(new Point(152, 23));
  792.                 labelIDEAInputK.setTabIndex(2);
  793.                 labelIDEAInputK.setTabStop(false);
  794.                 labelIDEAInputK.setText("");
  795.                 labelIDEAInputK.setVisible(false);
  796.  
  797.                 labelIDEACheckInputK.setFont(new Font("宋体", 14.0f, FontSize.POINTS, FontWeight.BOLD, false, false, false, CharacterSet.DEFAULT, 0));
  798.                 labelIDEACheckInputK.setLocation(new Point(16, 360));
  799.                 labelIDEACheckInputK.setSize(new Point(320, 20));
  800.                 labelIDEACheckInputK.setTabIndex(14);
  801.                 labelIDEACheckInputK.setTabStop(false);
  802.                 labelIDEACheckInputK.setText("");
  803.                 labelIDEACheckInputK.setVisible(false);
  804.                 labelIDEACheckInputK.setTextAlign(HorizontalAlignment.CENTER);
  805.  
  806.                 richEditIDEAKResult.setBackColor(new Color(204, 255, 51));
  807.                 richEditIDEAKResult.setFont(new Font("宋体", 14.0f, FontSize.POINTS, FontWeight.NORMAL, false, false, false, CharacterSet.DEFAULT, 0));
  808.                 richEditIDEAKResult.setForeColor(Color.WINDOWTEXT);
  809.                 richEditIDEAKResult.setLocation(new Point(376, 56));
  810.                 richEditIDEAKResult.setSize(new Point(400, 88));
  811.                 richEditIDEAKResult.setTabIndex(15);
  812.                 richEditIDEAKResult.setText("");
  813.                 richEditIDEAKResult.setVisible(false);
  814.                 richEditIDEAKResult.setReadOnly(true);
  815.                 richEditIDEAKResult.setScrollBars(RichEditScrollBars.FORCED_VERTICAL);
  816.  
  817.                 labelIDEAKResult.setFont(new Font("宋体", 15.0f, FontSize.POINTS, FontWeight.BOLD, false, false, false, CharacterSet.DEFAULT, 0));
  818.                 labelIDEAKResult.setLocation(new Point(384, 32));
  819.                 labelIDEAKResult.setSize(new Point(240, 23));
  820.                 labelIDEAKResult.setTabIndex(16);
  821.                 labelIDEAKResult.setTabStop(false);
  822.                 labelIDEAKResult.setText("");
  823.                 labelIDEAKResult.setVisible(false);
  824.  
  825.                 labelIDEAResult.setFont(new Font("宋体", 15.0f, FontSize.POINTS, FontWeight.BOLD, false, false, false, CharacterSet.DEFAULT, 0));
  826.                 labelIDEAResult.setLocation(new Point(384, 160));
  827.                 labelIDEAResult.setSize(new Point(240, 23));
  828.                 labelIDEAResult.setTabIndex(17);
  829.                 labelIDEAResult.setTabStop(false);
  830.                 labelIDEAResult.setText("");
  831.                 labelIDEAResult.setVisible(false);
  832.  
  833.                 menuItemHelp.setText("帮助");
  834.                 menuItemHelp.addOnClick(new EventHandler(this.menuItemHelp_click));
  835.  
  836.                 mainMenuIDEA.setMenuItems(new MenuItem[] {
  837.                                                                   menuItemIDEABegin,
  838.                                                                   menuItemIDEABack,
  839.                                                                   menuItemIDEAExit,
  840.                                                                   menuItemHelp});
  841.                 /* @designTimeOnly mainMenuIDEA.setLocation(new Point(112, -32)); */
  842.  
  843.                 this.setBackColor(new Color(153, 77, 0));
  844.                 this.setForeColor(Color.BLACK);
  845.                 this.setText("密码学-IDEA算法");
  846.                 this.setAutoScaleBaseSize(new Point(6, 12));
  847.                 this.setBorderStyle(FormBorderStyle.FIXED_3D);
  848.                 this.setClientSize(new Point(790, 531));
  849.                 this.setMaximizeBox(false);
  850.                 this.setMenu(mainMenuIDEA);
  851.                 this.setStartPosition(FormStartPosition.CENTER_SCREEN);
  852.  
  853.                 panelIDEA.setSize(new Point(792, 536));
  854.                 panelIDEA.setTabIndex(19);
  855.                 panelIDEA.setText("panel1");
  856.  
  857.                 pictureBoxIDEA.setLocation(new Point(112, 0));
  858.                 pictureBoxIDEA.setSize(new Point(680, 536));
  859.                 pictureBoxIDEA.setTabIndex(0);
  860.                 pictureBoxIDEA.setTabStop(false);
  861.                 pictureBoxIDEA.setText("pictureBox1");
  862.                 pictureBoxIDEA.setImage((Bitmap)resources.getObject("pictureBoxIDEA_image"));
  863.  
  864.                 richEditBegin.setBackColor(new Color(153, 77, 0));
  865.                 richEditBegin.setEnabled(false);
  866.                 richEditBegin.setFont(new Font("宋体", 16.0f));
  867.                 richEditBegin.setForeColor(new Color(204, 255, 51));
  868.                 richEditBegin.setLocation(new Point(8, 0));
  869.                 richEditBegin.setSize(new Point(32, 200));
  870.                 richEditBegin.setTabIndex(1);
  871.                 richEditBegin.setText("请点击开始按钮");
  872.                 richEditBegin.setBorderStyle(BorderStyle.NONE);
  873.  
  874.                 richEditzhuyi.setBackColor(new Color(153, 77, 0));
  875.                 richEditzhuyi.setEnabled(false);
  876.                 richEditzhuyi.setFont(new Font("宋体", 9.0f, FontSize.POINTS, FontWeight.NORMAL, false, false, false, CharacterSet.DEFAULT, 0));
  877.                 richEditzhuyi.setForeColor(new Color(204, 255, 51));
  878.                 richEditzhuyi.setLocation(new Point(8, 208));
  879.                 richEditzhuyi.setSize(new Point(96, 304));
  880.                 richEditzhuyi.setTabIndex(2);
  881.                 richEditzhuyi.setText("注意:      输入框内只能输入数字0到9和字母A到F,字母为大写。输入其余不符合上述条件的字符本软件均报错误。输入完毕后请点击右边的加脱密按钮即可开始运算。务必不要使用按下回车键来代替按下按钮,如使用了回车键,请将因为按下回车键产生的最后两位字符删去。");
  882.                 richEditzhuyi.setBorderStyle(BorderStyle.NONE);
  883.  
  884.                 this.setNewControls(new Control[] {
  885.                                                         panelIDEA,
  886.                                                         labelIDEAResult,
  887.                                                         labelIDEAKResult,
  888.                                                         richEditIDEAKResult,
  889.                                                         labelIDEACheckInputK,
  890.                                                         richEditIDEAResult,
  891.                                                         buttonIDEACalculate,
  892.                                                         labelIDEACheckInputMorC,
  893.                                                         comboBoxIDEAChangeDataFillType,
  894.                                                         buttonIDEAChangeDataFillType,
  895.                                                         labelIDEAChangeDataFillType,
  896.                                                         labelIDEADataFillType,
  897.                                                         richEditIDEAInputK,
  898.                                                         labelIDEAKlength,
  899.                                                         labelIDEAMorClength,
  900.                                                         richEditIDEAInputMorC,
  901.                                                         labelIDEAInputK,
  902.                                                         labelIDEAInputMorC,
  903.                                                         labelIDEAInstruction});
  904.                 panelIDEA.setNewControls(new Control[] {
  905.                                                                  richEditzhuyi,
  906.                                                                  richEditBegin,
  907.                                                                  pictureBoxIDEA});
  908.         }
  909.  
  910.         /**
  911.          * The main entry point for the application.
  912.          *
  913.          * @param args Array of parameters passed to the application
  914.          * via the command line.
  915.          */
  916.         public static void main(String args[])
  917.         {
  918.                 Application.run(new FormIDEAwindow());
  919.         }
  920. }
  921.  

回复 " IDEA加密工具"

这儿你可以回复上面这条便签

captcha