private static void OnSelectedAllOnGotFocusPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     if (d is TextBox)
     {
         TextBox box = d as TextBox;
         if ((bool)e.NewValue)
         {
             box.AddHandler(TextBox.PreviewMouseDownEvent, new MouseButtonEventHandler(TextBox_PreviewMouseDown));
             box.AddHandler(TextBox.GotFocusEvent, new RoutedEventHandler(TextBox_GotFocus));
             box.AddHandler(TextBox.LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus));
         }
         else
         {
             box.RemoveHandler(TextBox.MouseUpEvent, new MouseButtonEventHandler(TextBox_PreviewMouseDown));
             box.RemoveHandler(TextBox.GotFocusEvent, new RoutedEventHandler(TextBox_GotFocus));
             box.RemoveHandler(TextBox.LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus));
         }
     }
     else if (d is PasswordBox)
     {
         PasswordBox box = d as PasswordBox;
         if ((bool)e.NewValue)
         {
             box.AddHandler(PasswordBox.PreviewMouseDownEvent, new MouseButtonEventHandler(TextBox_PreviewMouseDown));
             box.AddHandler(PasswordBox.GotFocusEvent, new RoutedEventHandler(TextBox_GotFocus));
             box.AddHandler(PasswordBox.LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus));
         }
         else
         {
             box.RemoveHandler(PasswordBox.MouseUpEvent, new MouseButtonEventHandler(TextBox_PreviewMouseDown));
             box.RemoveHandler(PasswordBox.GotFocusEvent, new RoutedEventHandler(TextBox_GotFocus));
             box.RemoveHandler(PasswordBox.LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus));
         }
     }
 }
Пример #2
0
        // Setting panel for DES Algorithm
        #region SYMETRIC_ALG_INTERFACE
        private void AlgDraw(ref StackPanel sP, int panel)
        {
            switch (panel)
            {
            case 0:
                sP.Margin = new Thickness(20, 0, 0, 0);
                dynamic keyField;
                if (Encryption.algParams[0] == 0)
                {
                    keyField = new Button()
                    {
                        Style   = Resources["GenerateButton"] as Style,
                        Margin  = new Thickness(0, 5, 0, 5),
                        Width   = 347,
                        Content = "Згенерувати ключ"
                    };
                    keyField.AddHandler(Button.ClickEvent, new RoutedEventHandler(GenerateRng));
                }
                else
                {
                    keyField = new PasswordBox()
                    {
                        Style  = Resources["MainPasswordBox"] as Style,
                        Width  = 347,
                        Margin = new Thickness(0, 5, 0, 5)
                    };
                    keyField.AddHandler(PasswordBox.LostFocusEvent, new RoutedEventHandler(GeneratePass));
                }
                sP.Children.Add(keyField);
                break;

            case 1:
                sP.Margin = new Thickness(20, 0, 0, 0);
                var rngType = new RadioButton()
                {
                    Width     = 330,
                    Style     = Resources["MainRadioButton"] as Style,
                    Margin    = new Thickness(0, 5, 0, 0),
                    GroupName = "keyType",
                    IsChecked = Encryption.algParams[0] == 0 ? true : false
                };
                rngType.AddHandler(RadioButton.CheckedEvent, new RoutedEventHandler(KeyTypeRng));
                var rngTypeText = new TextBlock()
                {
                    Style = Resources["TextBlock"] as Style,
                    Text  = "Ключ з криптографічного генератора псевдовипадкових послідовностей"
                };

                var passType = new RadioButton()
                {
                    Width     = 330,
                    Style     = Resources["MainRadioButton"] as Style,
                    Margin    = new Thickness(0, 10, 0, 10),
                    GroupName = "keyType",
                    IsChecked = Encryption.algParams[0] == 1 ? true : false
                };
                passType.AddHandler(RadioButton.CheckedEvent, new RoutedEventHandler(KeyTypePass));
                var passTypeText = new TextBlock()
                {
                    Style = Resources["TextBlock"] as Style,
                    Text  = "Ключ генерується розширенням паролю"
                };
                rngType.Content  = rngTypeText;
                passType.Content = passTypeText;
                sP.Children.Add(rngType);
                sP.Children.Add(passType);
                break;

            case 2:
                sP.Margin = new Thickness(20, 0, 0, 0);
                var elements = new UIElement[3, 2]
                {
                    { new Label()
                      {
                          Style = Resources["ParamLabel"] as Style, Content = "Розмір блока (біт):"
                      }, Element(0) },
                    { new Label()
                      {
                          Style = Resources["ParamLabel"] as Style, Content = "Довжина ключа (біт):"
                      }, Element(1) },
                    { new Label()
                      {
                          Style = Resources["ParamLabel"] as Style, Content = "Кількість раундів:"
                      }, Element(2) }
                };
                for (int i = 0; i < elements.GetLength(0); i++)
                {
                    var wPc = new WrapPanel();
                    wPc.Children.Add(elements[i, 0]);
                    wPc.Children.Add(elements[i, 1]);
                    sP.Children.Add(wPc);
                }
                break;
            }
        }
Пример #3
0
        private UIElement DrawPassword()
        {
            var mainWP = new WrapPanel()
            {
                Style = Resources["WrapPanel"] as Style
            };
            var sP = new StackPanel()
            {
                Margin = new Thickness(10, 0, 0, 0),
                Style  = Resources["StackPanel"] as Style
            };

            sP.Children.Add(new Label()
            {
                Content                    = "Введіть паролі для генерації ключів:",
                HorizontalAlignment        = HorizontalAlignment.Stretch,
                HorizontalContentAlignment = HorizontalAlignment.Center
            });
            if (Encryption.currentAlg == 0)
            {
                int bytesPerPixel          = Encryption.CountBytesPerPixel(uploadedImg.Source as BitmapSource);
                List <WrapPanel> wPs       = new List <WrapPanel>();
                List <Brush>     colors    = new List <Brush>();
                List <string>    genLabels = new List <string>();
                if (bytesPerPixel == 1)
                {
                    wPs.Add(new WrapPanel());
                    colors.Add(Brushes.Gray);
                    genLabels.Add("Gray");
                }
                else
                {
                    wPs.AddRange(new[] {
                        new WrapPanel(),
                        new WrapPanel(),
                        new WrapPanel()
                    });

                    colors.AddRange(new[] {
                        Brushes.Red,
                        Brushes.Green,
                        Brushes.Blue
                    });
                    genLabels.AddRange(new[] {
                        "Red",
                        "Green",
                        "Blue"
                    });
                }
                int color = 0;
                foreach (WrapPanel wP in wPs)
                {
                    wP.Style  = Resources["WrapPanel"] as Style;
                    wP.Margin = new Thickness(0, 10, 0, 0);
                    var colorRect = new Rectangle();
                    colorRect.Style = Resources["ColorRectangle"] as Style;
                    colorRect.Fill  = colors[color];
                    wP.Children.Add(colorRect);
                    if (Encryption.algParams[3] == 1)
                    {
                        var generateField = new PasswordBox()
                        {
                            Style  = Resources["MainPasswordBox"] as Style,
                            Width  = 347,
                            Margin = new Thickness(5, 0, 0, 0),
                            Name   = genLabels[color] + "Pass",
                            Uid    = "0"
                        };
                        generateField.AddHandler(PasswordBox.LostFocusEvent, new RoutedEventHandler(GeneratePass));
                        wP.Children.Add(generateField);
                    }
                    else
                    {
                        for (int i = 0; i < Encryption.algParams[3]; i++)
                        {
                            var generateField = new PasswordBox()
                            {
                                Style  = Resources["MainPasswordBox"] as Style,
                                Margin = new Thickness(5, 0, 0, 0),
                                Width  = 171,
                                Name   = genLabels[color] + "Pass",
                                Uid    = i.ToString()
                            };
                            generateField.AddHandler(PasswordBox.LostFocusEvent, new RoutedEventHandler(GeneratePass));

                            wP.Children.Add(generateField);
                        }
                    }

                    sP.Children.Add(wP);
                    color++;
                }
            }
            else
            {
                var keyField = new PasswordBox()
                {
                    Style  = Resources["MainPasswordBox"] as Style,
                    Width  = 347,
                    Margin = new Thickness(0, 5, 0, 5)
                };
                keyField.AddHandler(PasswordBox.LostFocusEvent, new RoutedEventHandler(GeneratePass));
                sP.Children.Add(keyField);
            }
            mainWP.Children.Add(sP);
            return(mainWP);
        }
Пример #4
0
        // Setting panel for Transposition Algorithm
        #region TRANSPOSITION_ALG_INTERFACE
        private void TranspositionDraw(ref StackPanel sP, int panel)
        {
            switch (panel)
            {
            case 0:
                int bytesPerPixel = Encryption.CountBytesPerPixel(uploadedImg.Source as BitmapSource);
                if (Encryption.algParams[0] == 0)
                {
                    var generateAllBtn = new Button()
                    {
                        Style   = Resources["GenerateButton"] as Style,
                        Margin  = new Thickness(0, 5, 0, 0),
                        Width   = 240,
                        Content = "Згенерувати все",
                        Name    = "allRng",
                        Uid     = Encryption.CountBytesPerPixel(uploadedImg.Source as BitmapSource).ToString()
                    };
                    generateAllBtn.AddHandler(Button.ClickEvent, new RoutedEventHandler(GenerateRng));
                    sP.Children.Add(generateAllBtn);
                }

                List <WrapPanel> wPs       = new List <WrapPanel>();
                List <Brush>     colors    = new List <Brush>();
                List <string>    genLabels = new List <string>();
                if (bytesPerPixel == 1)
                {
                    wPs.Add(new WrapPanel());
                    colors.Add((SolidColorBrush) new BrushConverter().ConvertFrom("#BDBDBD"));
                    genLabels.Add("Gray");
                }
                else
                {
                    wPs.AddRange(new[] { new WrapPanel(),
                                         new WrapPanel(),
                                         new WrapPanel() });

                    colors.AddRange(new[] { (SolidColorBrush) new BrushConverter().ConvertFrom("#f44336"),
                                            (SolidColorBrush) new BrushConverter().ConvertFrom("#4CAF50"),
                                            (SolidColorBrush) new BrushConverter().ConvertFrom("#2196F3") });
                    genLabels.AddRange(new[] {
                        "Red",
                        "Green",
                        "Blue"
                    });
                }
                int color = 0;
                foreach (WrapPanel wP in wPs)
                {
                    wP.Style  = Resources["WrapPanel"] as Style;
                    wP.Margin = new Thickness(0, 10, 0, 0);
                    var colorRect = new Rectangle()
                    {
                        Style = Resources["ColorRectangle"] as Style,
                        Fill  = colors[color]
                    };
                    wP.Children.Add(colorRect);
                    if (Encryption.algParams[3] == 1)
                    {
                        dynamic generateField;
                        if (Encryption.algParams[0] == 0)
                        {
                            generateField = new Button()
                            {
                                Style   = Resources["GenerateButton"] as Style,
                                Width   = 347,
                                Margin  = new Thickness(5, 0, 0, 0),
                                Content = "Генерація для " + genLabels[color],
                                Name    = genLabels[color] + "Rng",
                                Uid     = "0"
                            };
                            generateField.AddHandler(Button.ClickEvent, new RoutedEventHandler(GenerateRng));
                        }
                        else
                        {
                            generateField = new PasswordBox()
                            {
                                Style  = Resources["MainPasswordBox"] as Style,
                                Width  = 347,
                                Margin = new Thickness(5, 0, 0, 0),
                                Name   = genLabels[color] + "Pass",
                                Uid    = "0"
                            };
                            generateField.AddHandler(PasswordBox.LostFocusEvent, new RoutedEventHandler(GeneratePass));
                        }
                        wP.Children.Add(generateField);
                    }
                    else
                    {
                        string[] labels = new string[] {
                            "Генерація для рядків",
                            "Генерація для стовпців"
                        };
                        for (int i = 0; i < labels.Length; i++)
                        {
                            dynamic generateField;
                            if (Encryption.algParams[0] == 0)
                            {
                                generateField = new Button()
                                {
                                    Style   = Resources["GenerateButton"] as Style,
                                    Margin  = new Thickness(5, 0, 0, 0),
                                    Width   = 171,
                                    Content = labels[i],
                                    Name    = genLabels[color] + "Rng",
                                    Uid     = i.ToString()
                                };
                                generateField.AddHandler(Button.ClickEvent, new RoutedEventHandler(GenerateRng));
                            }
                            else
                            {
                                generateField = new PasswordBox()
                                {
                                    Style  = Resources["MainPasswordBox"] as Style,
                                    Margin = new Thickness(5, 0, 0, 0),
                                    Width  = 171,
                                    Name   = genLabels[color] + "Pass",
                                    Uid    = i.ToString()
                                };
                                generateField.AddHandler(PasswordBox.LostFocusEvent, new RoutedEventHandler(GeneratePass));
                            }

                            wP.Children.Add(generateField);
                        }
                    }

                    sP.Children.Add(wP);
                    color++;
                }
                break;

            case 1:
                sP.Margin = new Thickness(20, 0, 0, 0);
                var rngType = new RadioButton()
                {
                    Width     = 330,
                    Style     = Resources["MainRadioButton"] as Style,
                    Margin    = new Thickness(0, 5, 0, 0),
                    GroupName = "keyType",
                    IsChecked = Encryption.algParams[0] == 0 ? true : false
                };
                rngType.AddHandler(RadioButton.CheckedEvent, new RoutedEventHandler(KeyTypeRng));
                var rngTypeText = new TextBlock()
                {
                    Style = Resources["TextBlock"] as Style,
                    Text  = "Ключ з криптографічного генератора псевдовипадкових послідовностей",
                };

                var passType = new RadioButton()
                {
                    Width     = 330,
                    Style     = Resources["MainRadioButton"] as Style,
                    Margin    = new Thickness(0, 10, 0, 10),
                    GroupName = "keyType",
                    IsChecked = Encryption.algParams[0] == 1 ? true : false
                };
                passType.AddHandler(RadioButton.CheckedEvent, new RoutedEventHandler(KeyTypePass));
                var passTypeText = new TextBlock()
                {
                    Style = Resources["TextBlock"] as Style,
                    Text  = "Ключ генерується розширенням паролю"
                };
                var inBlocks = new CheckBox()
                {
                    Style     = Resources["MainCheckBox"] as Style,
                    Content   = "Перестановки в середині блока",
                    Margin    = new Thickness(0, 5, 0, 0),
                    IsChecked = Encryption.algParams[1] == 1 ? true : false
                };
                inBlocks.AddHandler(CheckBox.ClickEvent, new RoutedEventHandler(InBlockEncription));
                rngType.Content  = rngTypeText;
                passType.Content = passTypeText;
                sP.Children.Add(rngType);
                sP.Children.Add(passType);
                sP.Children.Add(inBlocks);
                break;

            case 2:
                sP.Margin = new Thickness(20, 0, 0, 0);
                var label = new Label()
                {
                    Style   = Resources["ParamLabel"] as Style,
                    Content = "Розміри блока:"
                };
                List <string> cBItems = new List <string>()
                {
                    "256",
                    "128",
                    "64",
                    "32",
                    "16"
                };
                var comboBox = new ComboBox()
                {
                    Width         = 100,
                    Margin        = new Thickness(5, 0, 0, 0),
                    ItemsSource   = cBItems,
                    SelectedIndex = cBItems.IndexOf(Encryption.algParams[2].ToString())
                };
                comboBox.AddHandler(ComboBox.SelectionChangedEvent, new RoutedEventHandler(BlockSize));
                var wPc = new WrapPanel();
                wPc.Children.Add(label);
                wPc.Children.Add(comboBox);
                sP.Children.Add(wPc);
                var rowType = new RadioButton()
                {
                    Style     = Resources["MainRadioButton"] as Style,
                    Margin    = new Thickness(0, 5, 0, 0),
                    GroupName = "chipherType",
                    IsChecked = Encryption.algParams[3] == 1 ? true : false
                };
                rowType.AddHandler(RadioButton.CheckedEvent, new RoutedEventHandler(ChipherType1D));
                var rowTypeText = new TextBlock()
                {
                    Style = Resources["TextBlock"] as Style,
                    Text  = "Режим одномірного шифрування"
                };

                var colType = new RadioButton()
                {
                    Style     = Resources["MainRadioButton"] as Style,
                    Margin    = new Thickness(0, 10, 0, 10),
                    GroupName = "chipherType",
                    IsChecked = Encryption.algParams[3] == 2 ? true : false
                };
                var colTypeText = new TextBlock()
                {
                    Style = Resources["TextBlock"] as Style,
                    Text  = "Режим двомірного шифрування"
                };
                colType.AddHandler(RadioButton.CheckedEvent, new RoutedEventHandler(ChipherType2D));
                rowType.Content = rowTypeText;
                colType.Content = colTypeText;
                sP.Children.Add(rowType);
                sP.Children.Add(colType);
                break;
            }
        }
Пример #5
0
 public static void AddPasswordChangedHandler(this PasswordBox passBox, RoutedEventHandler handler)
 {
     passBox.AddHandler(MirrorPasswordChangedEvent, handler);
 }