예제 #1
0
        private void UpdateGuiWithRandomizedKeys(byte[] key)
        {
            var vd = new Validation();

            if (vd.CheckIfKeyIsEmpty(this)) // jeśli klucz jest pusty
            {
                txtKey.Text = vd.GetKeyString(key, rbKeyBytes.IsChecked == true ? KeyMode.Bytes : KeyMode.Chars);
            }

            if (vd.CheckIfRoundsNumIsEmpty(this))
            {
                txtRounds.Text = "32";
            }
        }
예제 #2
0
        private void PerformTextChangedValidation()
        {
            var   vd    = new Validation();
            Brush green = new SolidColorBrush(Color.FromArgb(0xFF, 0x70, 0x8C, 0x00));
            Brush red   = new SolidColorBrush(Color.FromArgb(0xFF, 0xE0, 0x51, 0x51));

            var vdResult = vd.ValidateForm(this, ActionType.ChangingText, out List <object> validationResults);

            if (vdResult || (byte[])validationResults?[0] != null)
            {
                var key = (byte[])validationResults[0];

                lblKeyValidation.Foreground = vdResult ? green : red;
                lblKeyValidation.Content    = $"Key: {key.Length * 8} bit{vd.GetWordEnding(key.Length * 8)} ({key.Length} byte{vd.GetWordEnding(key.Length)}) ({(vdResult ? "Correct" : "Incorrect")})";
            }
        }
예제 #3
0
        private void btnEncrypt_Click(object sender, RoutedEventArgs e)
        {
            var vd       = new Validation();
            var algMode  = rbStandardMode.IsChecked == true ? Mode.Standard : Mode.BitSlice;
            var encrMode = rbECBEncrMode.IsChecked == true ? EncryptionMode.ECB : EncryptionMode.CBC;

            if (vd.ValidateForm(this, ActionType.Encryption, out var validationResults))
            {
                var key    = (byte[])validationResults[0];
                var rounds = (int)validationResults[1];
                lblOperation.Content = "Encrypting...";

                ModifyGuiEventHandlers(OperationStatus.Start);
                ModifyGuiVisibility(OperationStatus.Start, sender);

                sw.Start();
                bgwEncrypt.RunWorkerAsync(new object[] { key, txtSourceFile.Text, rounds, algMode, encrMode }); // wywołuję operację szyfrowania asynchronicznie względem interfejsu użytkownika (dzięki czemu pozostaje on responsywny), przekazując zmienne do drugiego wątku w postaci tablicy obiektów.
            }
        }