Click here to Skip to main content
15,880,972 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
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);
            }
Posted
Comments
Richard MacCutchan 15-Sep-14 5:15am    
I see lots of indexed operations, it could be anywhere. You need to use your debugger and trap the error to see what values your indices have, and where the error occurs.
Member 11063279 15-Sep-14 5:17am    
how can i see it?? please help me?
Richard MacCutchan 15-Sep-14 5:46am    
Use your debugger like I suggested. No one else can guess what happens when your code runs with real data, or even which index is the one that causes the error.
Pheonyx 15-Sep-14 5:17am    
And what debugging have you done? What line of this code dump throws your common error that indicates you are trying to access something that is beyond the bounds of an array?
Member 11063279 15-Sep-14 5:19am    
whenever i execute the loop it's give the error, i tried to get the string and divided it into pieces in 8 size. but when i do it in loop it's give the error

1 solution

C#
f++;

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


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.
 
Share this answer
 
Comments
Member 11063279 15-Sep-14 5:50am    
but what the solution, it's necessary for it
Pheonyx 15-Sep-14 5:51am    
move f++ to the end of the loop.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900