Commits

Fydon committed cbd1460 Draft

Minor change. I prefer to explicitly label member variables as such

  • Participants
  • Parent commits 81f0b34

Comments (0)

Files changed (1)

CertificatePasswordRecovery/CertPasswordRecoveryForm.cs

             InitializeComponent();
 
             // Set Default log-level to '2' (see above for the key)
-            logLevelBx.SelectedIndex = 2;
-            LogLevel = logLevelBx.SelectedIndex;
+            this.logLevelBx.SelectedIndex = 2;
+            this.LogLevel = this.logLevelBx.SelectedIndex;
 
             // Set the 'Starting String' max character limit
-            startStringBx.MaxLength = (int)maxGenBx.Value;
+            this.startStringBx.MaxLength = (int)this.maxGenBx.Value;
         }
 
         /// <summary>
         private void recoverPasswordBtn_Click(object sender, EventArgs e)
         {
             // Make sure the user is warned when non-sequenced values are in the 'starting string' box
-            char[] starting_chars = startStringBx.Text.ToCharArray();
+            char[] starting_chars = this.startStringBx.Text.ToCharArray();
             bool ContainsInvalidChars = false;
             foreach (char character in starting_chars)
             {
-                if (symbolSequenceBx.Text.IndexOf(character) == -1)
+                if (this.symbolSequenceBx.Text.IndexOf(character) == -1)
                 {
                     ContainsInvalidChars = true;
                 }
 
 
             // Make sure we have a valid path to a file entered in the certificate box
-            if (!File.Exists(pathToCertBx.Text))
+            if (!File.Exists(this.pathToCertBx.Text))
             {
                 MessageBox.Show("No Certificate file selected. Please ensure one is selected before continuing!", "Error");
                 return;
             }
 
             // Make sure we have a valid log file path entered (if logging is not set to 0)
-            if((LogLevel != 0) && !(logPathBx.Text.Length > 0))
+            if((this.LogLevel != 0) && !(this.logPathBx.Text.Length > 0))
             {
                 MessageBox.Show("No log file path selected. Please enter a path before continuing!", "Error");
                 return;
             }
 
             // Disable controls (make them read-only)
-            maxGenBx.ReadOnly = true;
-            startStringBx.ReadOnly = true;
-            prefixBx.ReadOnly = true;
-            suffixBx.ReadOnly = true;
-            symbolSequenceBx.ReadOnly = true;
-            pathToCertBx.ReadOnly = true;
-            logPathBx.ReadOnly = true;
-            logLevelBx.Enabled = false;
-            recoverPasswordBtn.Enabled = false;
+            this.maxGenBx.ReadOnly = true;
+            this.startStringBx.ReadOnly = true;
+            this.prefixBx.ReadOnly = true;
+            this.suffixBx.ReadOnly = true;
+            this.symbolSequenceBx.ReadOnly = true;
+            this.pathToCertBx.ReadOnly = true;
+            this.logPathBx.ReadOnly = true;
+            this.logLevelBx.Enabled = false;
+            this.recoverPasswordBtn.Enabled = false;
 
             // Make the progress bar visible:
-            progressBar.Style = ProgressBarStyle.Marquee;
-            progressBar.Visible = true;
+            this.progressBar.Style = ProgressBarStyle.Marquee;
+            this.progressBar.Visible = true;
 
             // If Logging is NOT set to 0, log a message indicating that we've started Logging
-            if (LogLevel != 0)
+            if (this.LogLevel != 0)
             {
-                Log("-----------------\r\n-----------------\r\nBeginning to Recover password (Brute-force)", logPathBx.Text, 0);
+                Log("-----------------\r\n-----------------\r\nBeginning to Recover password (Brute-force)", this.logPathBx.Text, 0);
             }
 
             // Read the certificate into memory
-            this.certificateData = File.ReadAllBytes(pathToCertBx.Text);
+            this.certificateData = File.ReadAllBytes(this.pathToCertBx.Text);
 
             // Kick off a thread which does the work
             BackgroundWorker PasswordRecoveryWorker = new BackgroundWorker();
         void PasswordRecoveryWorker_DoWork(object sender, DoWorkEventArgs e)
         {
             // Create password character array of the size specified
-            password = new int[(int)maxGenBx.Value];
+            this.password = new int[(int)this.maxGenBx.Value];
 
             // Initialise the character array, so that when the character is incremented for the first time it will be the first character in the sequence
-            for( int startingPasswordIndex = 0; startingPasswordIndex < password.Length; ++startingPasswordIndex )
+            for( int startingPasswordIndex = 0; startingPasswordIndex < this.password.Length; ++startingPasswordIndex )
             {
-                password[startingPasswordIndex] = -1;
+                this.password[startingPasswordIndex] = -1;
             }
 
             // Populate the character sequence we should use during the brute-force password recovery
-            string[] character_candidates = symbolSequenceBx.Text.Split(',');
-            sequence = new char[character_candidates.Length];
+            string[] character_candidates = this.symbolSequenceBx.Text.Split(',');
+            this.sequence = new char[character_candidates.Length];
             int i = 0;
             foreach (string char_candidate in character_candidates)
             {
                 }
 
                 // If the character is just a single character we can add it to the sequence list
-                sequence[i] = char_candidate_after_comma_check[0];
+                this.sequence[i] = char_candidate_after_comma_check[0];
 
                 // Increment the position counter for sequence
                 i++;
         {
             // Get the characters of the 'starting string'
             //  Reverse them so we start with the 'lowest' order characters and work our way up
-            char[] starting_chars = startStringBx.Text.ToCharArray();
+            char[] starting_chars = this.startStringBx.Text.ToCharArray();
             Array.Reverse(starting_chars);
             
             // Map them to integers that correspond with the character sequence
             int count = 0;
             foreach (char character in starting_chars)
             {
-                for (int i = 0; i < sequence.Length; i++)
+                for (int i = 0; i < this.sequence.Length; i++)
                 {
-                    if (character == sequence[i])
+                    if (character == this.sequence[i])
                     {
                         starting_chars_converted[count] = i;
                         break;
 
             // Assign the characters one at a time (starting with the lowest) to the password array
             int pos = 0;
-            int startingPasswordCharacterIndex = password.Length -1;
+            int startingPasswordCharacterIndex = this.password.Length -1;
             for( ; startingPasswordCharacterIndex >= 0; startingPasswordCharacterIndex-- )
             {
                 // Exit if we have exausted the starting characters (don't want outofbounds exception)
                 {
                     break;
                 }
-                password[startingPasswordCharacterIndex] = starting_chars_converted[pos];
+                this.password[startingPasswordCharacterIndex] = starting_chars_converted[pos];
                 pos++;
             }
 
         void PasswordRecoveryWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
         {
             // Re-enable the controls
-            maxGenBx.ReadOnly = false;
-            startStringBx.ReadOnly = false;
-            prefixBx.ReadOnly = false;
-            suffixBx.ReadOnly = false;
-            symbolSequenceBx.ReadOnly = false;
-            pathToCertBx.ReadOnly = false;
-            logPathBx.ReadOnly = false;
-            logLevelBx.Enabled = true;
-            recoverPasswordBtn.Enabled = true;
+            this.maxGenBx.ReadOnly = false;
+            this.startStringBx.ReadOnly = false;
+            this.prefixBx.ReadOnly = false;
+            this.suffixBx.ReadOnly = false;
+            this.symbolSequenceBx.ReadOnly = false;
+            this.pathToCertBx.ReadOnly = false;
+            this.logPathBx.ReadOnly = false;
+            this.logLevelBx.Enabled = true;
+            this.recoverPasswordBtn.Enabled = true;
 
             // Make the progress bar invisible:
-            progressBar.Style = ProgressBarStyle.Blocks;
-            progressBar.Visible = false;
+            this.progressBar.Style = ProgressBarStyle.Blocks;
+            this.progressBar.Visible = false;
         }
 
         /// <summary>
         private void RecoverPassword()
         {
             // Find the 'depth' of the password array
-            int depth = password.Length - 1;
+            int depth = this.password.Length - 1;
 
             // Incrementors needed to ensure we check every password combination
             BigInteger i = 1;
             bool password_found = false;
 
             // Reset counter
-            logIterationCount = 1;
+            this.logIterationCount = 1;
 
-            char[] password_sequenced = new char[password.Length];
+            char[] password_sequenced = new char[this.password.Length];
 
             // Setup the initial sequenced characters
-            for( int pos = 0; pos < password.Length; pos++ )
+            for( int pos = 0; pos < this.password.Length; pos++ )
             {
-                if( password[pos] != -1 )
+                if( this.password[pos] != -1 )
                 {
-                    password_sequenced[pos] = sequence[password[pos]];
+                    password_sequenced[pos] = this.sequence[this.password[pos]];
                 }
             }
 
             do
             {
                 // Increment the highest position of the array
-                password[depth]++;
+                this.password[depth]++;
 
                 // Check for overflows in ALL array positions, starting from the "deepest" (The lowest)
                 int overflowedCharacterIndex = depth;
                     // If there is an overflow:
                     //      Clear the current position back to sequence[0]
                     //      Increment the next lower position
-                    if (password[overflowedCharacterIndex] > (sequence.Length - 1))
+                    if (this.password[overflowedCharacterIndex] > (this.sequence.Length - 1))
                     {
-                        password[overflowedCharacterIndex] = 0;
+                        this.password[overflowedCharacterIndex] = 0;
 
                         // Prevent array out of bounds problem
                         if (overflowedCharacterIndex != 0)
                         {
-                            password[overflowedCharacterIndex - 1]++;
+                            this.password[overflowedCharacterIndex - 1]++;
                         }
                     }
                     else
                 //
                 // Create a string based on the sequenced characters
                 //
-                for (int pos = overflowedCharacterIndex; pos < password.Length; pos++)
+                for (int pos = overflowedCharacterIndex; pos < this.password.Length; pos++)
                 {
-                    password_sequenced[pos] = sequence[password[pos]];
+                    password_sequenced[pos] = this.sequence[this.password[pos]];
                 }
                 string pw = new string(password_sequenced, this.indexOfFirstCharacterInCurrentPassword, password_sequenced.Length - this.indexOfFirstCharacterInCurrentPassword);
                 // Prepend the 'prefix' string (if one is entered)
-                if (prefixBx.Text.Length > 0)
+                if (this.prefixBx.Text.Length > 0)
                 {
-                    pw = prefixBx.Text + pw;
+                    pw = this.prefixBx.Text + pw;
                 }
                 // Append the 'suffix' string (if one is entered)
-                if (suffixBx.Text.Length > 0)
+                if (this.suffixBx.Text.Length > 0)
                 {
-                    pw = pw + suffixBx.Text;
+                    pw = pw + this.suffixBx.Text;
                 }
 
                 // Check the password
                 //  If it is found, exit the loop
-                if (TestPassword(this.certificateData, pw, logPathBx.Text, i))
+                if (TestPassword(this.certificateData, pw, this.logPathBx.Text, i))
                 {
                     password_found = true;
                 }
         {
             try
             {
-                certificate = new X509Certificate2(certificateData, CertificatePassword);
+                this.certificate = new X509Certificate2(certificateData, CertificatePassword);
                 
                 // Only log successful crack to a file if the logging is NOT set to 0!
                 //      You may do this if you don't want to have a "paper trail" of your password
-                if (LogLevel != 0)
+                if (this.LogLevel != 0)
                 {
                     Log("Found Password: " + CertificatePassword, LogFileLocation, PasswordNumber);
                 }
             {
                 // If we don't find the password (likely at first, given the sheer number of possible passwords)
                 //  Handle logging in accordance with the user's settings
-                switch (LogLevel)
+                switch (this.LogLevel)
                 {
                     // Case 1 is handled in the "success" section above. We should ALWAYS log the success unless told not to.
                     // Case 0 is handled in the "success" section. We just don't log anything when told not to!
 
             if (certificateBrowser.ShowDialog() == DialogResult.OK)
             {
-                pathToCertBx.Text = certificateBrowser.FileName;
+                this.pathToCertBx.Text = certificateBrowser.FileName;
             }
         }
 
         /// <param name="e"></param>
         private void maxGenBx_ValueChanged(object sender, EventArgs e)
         {
-            startStringBx.MaxLength = (int)maxGenBx.Value;
+            this.startStringBx.MaxLength = (int)this.maxGenBx.Value;
         }
 
         /// <summary>
         /// <param name="e"></param>
         private void logLevelBx_SelectedIndexChanged(object sender, EventArgs e)
         {
-            LogLevel = logLevelBx.SelectedIndex;
+            this.LogLevel = this.logLevelBx.SelectedIndex;
         }
 
         /// <summary>