我的代码给出的问题是“索引是否超出了界限的范围”我需要帮助?/

问题描述:

try
            {

                if (txtB_Passowrd.Text != "")
                {

                                       string str;
                                        int chunkLength = 8;
                                        str = txtB_Passowrd.Text;

                                        for (int l = 0; l < str.Length; l += chunkLength)
                                        {
                                            if (chunkLength + l > str.Length)
                                                chunkLength = str.Length - l;
                                         //        MessageBox.Show(" "+str.Substring(l, chunkLength));
                                       //       richTextBox2.Text= str.Substring(i, chunkLength);
                                            listBox1.Items.Add(str.Substring(l, chunkLength));
                                        }
                                        int r = listBox1.Items.Count;
                //    MessageBox.Show("Test"+r);
                                        int f = 0;
                                        while (f<r)
                                        {


                    viewSubKeysToolStripMenuItem1.Enabled = true;
                        f++;

                        name = BinaryConversion.GetPassword(listBox1.Items[f].ToString());
                        // txtB_Passowrd.Text = name;
                        if (f == r)
                            break;

                        txtB_64BitBinary.Text = BinaryConversion.ConvertToBinary64(name);
                        txtB_64Binary_Parity.Text = BinaryConversion.parityBitAdd(name);
                        Bit64Array = txtB_64Binary_Parity.Text;
                        Bit56Array = Permutation.Pc1(Bit64Array);
                        for (int i = 0; i < 56; i++)
                        {
                            txtB_56BitBinary.Text = txtB_56BitBinary.Text + Bit56Array[i];

                        }

                        for (int K = 0; K < 28; K++)
                        {
                            L28[K] = Bit56Array[K];
                            R28[K] = Bit56Array[K + 28];

                        }



                        int round = 1;
                        for (int i = 0; i < 16; i++)
                        {
                            if (round == 1 || round == 2 || round == 9 || round == 16)
                            {
                                L28 = Permutation.LeftShift1Bit(L28);
                                R28 = Permutation.LeftShift1Bit(R28);

                            }
                            else
                            {
                                for (int j = 0; j < 2; j++)
                                {

                                    L28 = Permutation.LeftShift1Bit(L28);
                                    R28 = Permutation.LeftShift1Bit(R28);

                                }

                            }
                            for (int j = 0; j < 28; j++)
                            {
                                Bit56Array[j] = L28[j];
                                Bit56Array[j + 28] = R28[j];

                            }
                            SecretK16Keys[i] = Permutation.Pc2(Bit56Array);
                            round++;
                        }


                    }
              }
                else
                {
                    MessageBox.Show("You Must Enter Password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception obj)
            {
                MessageBox.Show(obj.Message.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

f++;

  name = BinaryConversion.GetPassword(listBox1.Items[f].ToString());





It可能是那条线,它可能是你的其他线的负载,但你在使用之前递增f。所以这可能会抛出你的错误,因为f等于listBox1.Items.Count的计数值,导致你的错误,因为它不应该被允许增加到那个值。



It could be that line there,it could be a load of your other lines, but you are incrementing f before you use it. So this could be throwing your error as f becomes equal to the count value of listBox1.Items.Count, resulting in your error as it should not be allowed to increase to that value.