private static void Lexp_Expanded(object sender, RoutedEventArgs e) { Expander exp = sender as Expander; int x = expanders.IndexOf(exp); rows[x * 2 + 1].Height = new GridLength(24 + expandedHeight); canvas1.Height = canvas1.Height + expandedHeight; grid1.Height = grid1.Height + expandedHeight; sBound.Height = sBound.Height + expandedHeight; expTb = new TextBox { IsReadOnly = true, Margin = new Thickness(0, 24, 0, 0), Padding = new Thickness(0, 5, 0, 5), Width = 608, Text = "", FontFamily = new FontFamily("Courier New") }; Grid.SetColumn(expTb, 0); Grid.SetColumnSpan(expTb, 16); Grid.SetRow(expTb, x * 2 + 1); grid1.Children.Add(expTb); List <byte> coefficients = new List <byte> { 148, 32, 133, 16, 194, 192, 1, 251, 1, 192, 194, 16, 133, 32, 148, 1 }; UInt16 ans = 0; for (int i = 0; i < 16; ++i) { expTb.Text += "a" + Convert.ToString(15 - i, 10).PadLeft(2, '0') + ") " + textBoxes[x][i].Text.PadLeft(2, ' ') + " = " + Convert.ToString(vectors[x][i], 2).PadLeft(8, '0') + ", " + "c" + Convert.ToString(15 - i, 10).PadLeft(2, '0') + ") " + Convert.ToString(coefficients[i], 10).PadLeft(3, ' ') + " = " + Convert.ToString(coefficients[i], 2).PadLeft(8, '0') + ". " + "\n"; ans ^= Kuznyechik.mul(vectors[x][i], coefficients[i]); } for (int i = 0; i < 16; ++i) { expTb.Text += "a" + Convert.ToString(15 - i, 10).PadLeft(2, '0') + " * " + "c" + Convert.ToString(15 - i, 10).PadLeft(2, '0') + " = " + Convert.ToString(vectors[x][i], 2).PadLeft(8, '0') + " * " + Convert.ToString(coefficients[i], 2).PadLeft(8, '0') + " = " + Convert.ToString(Kuznyechik.mul(vectors[x][i], coefficients[i]), 2).PadLeft(16, '0') + "\n"; } expTb.Text += "Σ(ai * ci) = " + Convert.ToString(ans, 2).PadLeft(16, '0') + "\n"; expTb.Text += "Σ(ai * ci) mod x8 + x7 + x6 + x + 1 = " + Convert.ToString(Kuznyechik.norm(ans), 2).PadLeft(8, '0') + " = " + Convert.ToString(Kuznyechik.norm(ans), 16).PadLeft(2, '0').ToUpper(); coefficients.Clear(); isActive = true; }
public static void GenerateContent(MainWindow mainWindow, List <byte> input) { object wantedNode = mainWindow.FindName("mainGrid"); Grid mainGrid = wantedNode as Grid; mainSV = new ScrollViewer { VerticalScrollBarVisibility = ScrollBarVisibility.Visible, Height = 630, Width = 653, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(0, 20, 0, 0) }; Grid.SetRow(mainSV, 1); mainGrid.Children.Add(mainSV); canvas1 = new Canvas() { Height = 812, Width = 636 }; mainSV.Content = canvas1; sBound = new Rectangle { Height = 812, Width = 636, Fill = Brushes.LightGray, Stroke = Brushes.Black }; canvas1.Children.Add(sBound); grid1 = new Grid() { Margin = new Thickness(10, 10, 10, 10) }; rows = new List <RowDefinition>(); for (int i = 0; i < 33; ++i) { rows.Add(new RowDefinition()); rows[i].Height = new GridLength(24); grid1.RowDefinitions.Add(rows[i]); } columns = new List <ColumnDefinition>(); for (int i = 0; i < 16; ++i) { columns.Add(new ColumnDefinition()); columns[i].Width = new GridLength(38); grid1.ColumnDefinitions.Add(columns[i]); } canvas1.Children.Add(grid1); vectors = new List <List <byte> >(); vectors.Add(new List <byte>(input)); textBoxes = new List <List <TextBox> >(); expanders = new List <Expander>(); for (int i = 0; i < 17; ++i) { textBoxes.Add(new List <TextBox>()); for (int j = 0; j < 16; ++j) { textBoxes[i].Add(new TextBox { IsReadOnly = true, Text = BitConverter.ToString((new List <byte> { vectors[i][j] }).ToArray()), TextAlignment = TextAlignment.Center, Margin = new Thickness(0, 2, 0, 2) }); Grid.SetColumn(textBoxes[i][j], j); Grid.SetRow(textBoxes[i][j], i * 2); grid1.Children.Add(textBoxes[i][j]); } vectors.Add(Kuznyechik.reversed_R(vectors[i])); if (i == 16) { break; } byte t = vectors[i][0]; for (int k = 0; k < 15; ++k) { vectors[i][k] = vectors[i][k + 1]; } vectors[i][15] = t; Label ans = new Label { Content = "l(" + BitConverter.ToString(vectors[i].ToArray()) + ") = " + BitConverter.ToString((new List <byte> { vectors[i + 1][15] }).ToArray()), HorizontalContentAlignment = HorizontalAlignment.Left, FontStyle = FontStyles.Italic }; Grid.SetColumn(ans, 0); Grid.SetColumnSpan(ans, 16); Grid.SetRow(ans, i * 2 + 1); grid1.Children.Add(ans); ans.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); Expander lexp = new Expander { HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(Convert.ToInt32(ans.DesiredSize.Width) + 5, 0, 0, 0) }; Grid.SetColumn(lexp, 0); Grid.SetColumnSpan(lexp, 16); Grid.SetRow(lexp, i * 2 + 1); grid1.Children.Add(lexp); expanders.Add(lexp); lexp.Expanded += Lexp_Expanded; lexp.Collapsed += Lexp_Collapsed; } isActive = true; }
public static void GenerateContent(MainWindow mainWindow, Kuznyechik k) { textBlocks.Clear(); buttons.Clear(); object wantedNode = mainWindow.FindName("cryptTabScroller"); ScrollViewer cryptTabScroller = wantedNode as ScrollViewer; Grid encryptGrid = new Grid { Height = 1440, Width = 640, Margin = new Thickness(20, 20, 20, 20), HorizontalAlignment = HorizontalAlignment.Left }; List <ColumnDefinition> columns = new List <ColumnDefinition>(); for (int i = 0; i < 8; ++i) { columns.Add(new ColumnDefinition()); } columns[0].Width = new GridLength(20); columns[1].Width = new GridLength(140); columns[2].Width = new GridLength(60); columns[3].Width = new GridLength(140); columns[4].Width = new GridLength(60); columns[5].Width = new GridLength(140); columns[6].Width = new GridLength(60); columns[7].Width = new GridLength(20); for (int i = 0; i < 8; ++i) { encryptGrid.ColumnDefinitions.Add(columns[i]); } List <RowDefinition> rows = new List <RowDefinition>(); for (int i = 0; i < 29; ++i) { rows.Add(new RowDefinition()); } rows[0].Height = new GridLength(60); rows[1].Height = new GridLength(30); rows[2].Height = new GridLength(60); rows[3].Height = new GridLength(60); rows[4].Height = new GridLength(30); rows[5].Height = new GridLength(60); rows[6].Height = new GridLength(60); rows[7].Height = new GridLength(30); rows[8].Height = new GridLength(60); rows[9].Height = new GridLength(60); rows[10].Height = new GridLength(30); rows[11].Height = new GridLength(60); rows[12].Height = new GridLength(60); rows[13].Height = new GridLength(30); rows[14].Height = new GridLength(60); rows[15].Height = new GridLength(60); rows[16].Height = new GridLength(30); rows[17].Height = new GridLength(60); rows[18].Height = new GridLength(60); rows[19].Height = new GridLength(30); rows[20].Height = new GridLength(60); rows[21].Height = new GridLength(60); rows[22].Height = new GridLength(30); rows[23].Height = new GridLength(60); rows[24].Height = new GridLength(60); rows[25].Height = new GridLength(30); rows[26].Height = new GridLength(60); rows[27].Height = new GridLength(60); rows[28].Height = new GridLength(30); for (int i = 0; i < 29; ++i) { encryptGrid.RowDefinitions.Add(rows[i]); } cryptTabScroller.Content = encryptGrid; List <Line> lines = new List <Line>(); List <Polygon> polygons = new List <Polygon>(); List <Label> labels = new List <Label>(); for (int i = 0; i <= 9; ++i) { for (int j = 0; j < 3; ++j) { TextBlock tb0 = new TextBlock { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Bottom, Foreground = new SolidColorBrush(Color.FromRgb(127, 127, 127)), FontStyle = FontStyles.Italic }; tb0.Inlines.Add(BitConverter.ToString(k.cryptRounds[3 * i + j].ToArray()).Replace("-", "").Substring(0, 16) + "\n" + BitConverter.ToString(k.cryptRounds[3 * i + j].ToArray()).Replace("-", "").Substring(16, 16)); Grid.SetColumn(tb0, 1 + j * 2); Grid.SetRow(tb0, i * 3); textBlocks.Add(tb0); encryptGrid.Children.Add(tb0); if (i == 9) { break; } Line t1 = new Line { Stroke = Brushes.Black, X1 = 0, Y1 = 15, X2 = 140, Y2 = 15 }; Grid.SetColumn(t1, 1 + j * 2); Grid.SetRow(t1, i * 3 + 1); RenderOptions.SetEdgeMode(t1, EdgeMode.Aliased); lines.Add(t1); encryptGrid.Children.Add(t1); Polygon p1 = new Polygon { Fill = Brushes.Black, Points = new PointCollection(new List <Point> { new Point(140, 15), new Point(130, 12), new Point(130, 18) }), }; Grid.SetColumn(p1, 1 + j * 2); Grid.SetRow(p1, i * 3 + 1); polygons.Add(p1); encryptGrid.Children.Add(p1); } Label l0 = new Label { Content = "K" + i.ToString(), FontFamily = new FontFamily("Times New Roman"), FontSize = 16, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Center }; Grid.SetColumn(l0, 2); Grid.SetRow(l0, i * 3); labels.Add(l0); encryptGrid.Children.Add(l0); Line vertt = new Line { Stroke = Brushes.Black, X1 = 30, Y1 = 25, X2 = 30, Y2 = 60 }; Grid.SetColumn(vertt, 2); Grid.SetRow(vertt, i * 3); RenderOptions.SetEdgeMode(vertt, EdgeMode.Aliased); lines.Add(vertt); encryptGrid.Children.Add(vertt); Polygon vertp = new Polygon { Fill = Brushes.Black, Points = new PointCollection(new List <Point> { new Point(30, 60), new Point(27, 50), new Point(33, 50) }), }; Grid.SetColumn(vertp, 2); Grid.SetRow(vertp, i * 3); polygons.Add(vertp); encryptGrid.Children.Add(vertp); Line t0 = new Line { Stroke = Brushes.Black, X1 = 19, Y1 = 15, X2 = 40, Y2 = 15 }; Grid.SetColumn(t0, 0); Grid.SetRow(t0, i * 3 + 1); RenderOptions.SetEdgeMode(t0, EdgeMode.Aliased); lines.Add(t0); encryptGrid.Children.Add(t0); Button x = new Button { Content = "X", FontFamily = new FontFamily("Times New Roman"), FontSize = 18, Background = Brushes.Transparent }; Grid.SetColumn(x, 2); Grid.SetRow(x, i * 3 + 1); buttons.Add(x); encryptGrid.Children.Add(x); x.Click += new RoutedEventHandler(mainWindow.X_Click); if (i == 9) { break; } Button s = new Button { Content = "S", FontFamily = new FontFamily("Times New Roman"), FontSize = 18, Background = Brushes.Transparent, }; Grid.SetColumn(s, 4); Grid.SetRow(s, i * 3 + 1); buttons.Add(s); encryptGrid.Children.Add(s); s.Click += new RoutedEventHandler(mainWindow.S_Click); Button l = new Button { Content = "L", FontFamily = new FontFamily("Times New Roman"), FontSize = 18, Background = Brushes.Transparent }; Grid.SetColumn(l, 6); Grid.SetRow(l, i * 3 + 1); buttons.Add(l); encryptGrid.Children.Add(l); l.Click += new RoutedEventHandler(mainWindow.L_Click); Line t3 = new Line { Stroke = Brushes.Black, X1 = 0, Y1 = 15, X2 = 20, Y2 = 15 }; Grid.SetColumn(t3, 7); Grid.SetRow(t3, i * 3 + 1); RenderOptions.SetEdgeMode(t3, EdgeMode.Aliased); lines.Add(t3); encryptGrid.Children.Add(t3); Line t4 = new Line { Stroke = Brushes.Black, X1 = 20, Y1 = 15, X2 = 20, Y2 = 70 }; Grid.SetColumn(t4, 7); Grid.SetRow(t4, i * 3 + 1); Grid.SetRowSpan(t4, 2); RenderOptions.SetEdgeMode(t4, EdgeMode.Aliased); lines.Add(t4); encryptGrid.Children.Add(t4); Line t5 = new Line { Stroke = Brushes.Black, X1 = 20, Y1 = 40, X2 = 640, Y2 = 40 }; Grid.SetColumn(t5, 0); Grid.SetColumnSpan(t5, 8); Grid.SetRow(t5, i * 3 + 2); RenderOptions.SetEdgeMode(t5, EdgeMode.Aliased); lines.Add(t5); encryptGrid.Children.Add(t5); Line t6 = new Line { Stroke = Brushes.Black, X1 = 20, Y1 = 40, X2 = 20, Y2 = 135 }; Grid.SetColumn(t6, 0); Grid.SetRowSpan(t6, 3); Grid.SetRow(t6, i * 3 + 2); RenderOptions.SetEdgeMode(t6, EdgeMode.Aliased); lines.Add(t6); encryptGrid.Children.Add(t6); } Line tt0 = new Line { Stroke = Brushes.Black, X1 = 19, Y1 = 15, X2 = 160, Y2 = 15 }; Grid.SetColumn(tt0, 0); Grid.SetColumnSpan(tt0, 2); Grid.SetRow(tt0, 28); RenderOptions.SetEdgeMode(tt0, EdgeMode.Aliased); lines.Add(tt0); encryptGrid.Children.Add(tt0); Polygon tp0 = new Polygon { Fill = Brushes.Black, Points = new PointCollection(new List <Point> { new Point(140, 15), new Point(130, 12), new Point(130, 18) }), }; Grid.SetColumn(tp0, 1); Grid.SetRow(tp0, 28); polygons.Add(tp0); encryptGrid.Children.Add(tp0); TextBlock lasttb = new TextBlock { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Bottom, Foreground = new SolidColorBrush(Color.FromRgb(127, 127, 127)), FontStyle = FontStyles.Italic }; lasttb.Inlines.Add(BitConverter.ToString(k.ciphertext.ToArray()).Replace("-", "").Substring(0, 16) + "\n" + BitConverter.ToString(k.ciphertext.ToArray()).Replace("-", "").Substring(16, 16)); Grid.SetColumn(lasttb, 3); Grid.SetRow(lasttb, 27); textBlocks.Add(lasttb); encryptGrid.Children.Add(lasttb); Line tt1 = new Line { Stroke = Brushes.Black, X1 = 0, Y1 = 15, X2 = 440, Y2 = 15 }; Grid.SetColumn(tt1, 3); Grid.SetColumnSpan(tt1, 5); Grid.SetRow(tt1, 28); RenderOptions.SetEdgeMode(tt1, EdgeMode.Aliased); lines.Add(tt1); encryptGrid.Children.Add(tt1); Polygon tp1 = new Polygon { Fill = Brushes.Black, Points = new PointCollection(new List <Point> { new Point(20, 15), new Point(10, 12), new Point(10, 18) }), }; Grid.SetColumn(tp1, 7); Grid.SetRow(tp1, 28); polygons.Add(tp1); encryptGrid.Children.Add(tp1); }
public static void GenerateContent(MainWindow mainWindow, Kuznyechik k) { textBlocks.Clear(); buttons.Clear(); object wantedNode = mainWindow.FindName("keyTabScroller"); ScrollViewer keyTabScroller = wantedNode as ScrollViewer; ////////////////////////////GRID Gefinition//////////////////////////////////// Grid keyGrid = new Grid { Height = 7710, Width = 740, Margin = new Thickness(20, 20, 20, 20), HorizontalAlignment = HorizontalAlignment.Left }; List <ColumnDefinition> columns = new List <ColumnDefinition>(); for (int i = 0; i < 8; ++i) { columns.Add(new ColumnDefinition()); } columns[0].Width = new GridLength(60); columns[1].Width = new GridLength(140); columns[2].Width = new GridLength(60); columns[3].Width = new GridLength(140); columns[4].Width = new GridLength(60); columns[5].Width = new GridLength(140); columns[6].Width = new GridLength(60); columns[7].Width = new GridLength(80); for (int i = 0; i < 8; ++i) { keyGrid.ColumnDefinitions.Add(columns[i]); } List <RowDefinition> rows = new List <RowDefinition>(); for (int i = 0; i < 193; ++i) { rows.Add(new RowDefinition()); } for (int i = 0; i < 32; ++i) { rows[i * 6 + 0].Height = new GridLength(30); rows[i * 6 + 1].Height = new GridLength(60); rows[i * 6 + 2].Height = new GridLength(30); rows[i * 6 + 3].Height = new GridLength(30); rows[i * 6 + 4].Height = new GridLength(60); rows[i * 6 + 5].Height = new GridLength(30); } for (int i = 0; i < 193; ++i) { keyGrid.RowDefinitions.Add(rows[i]); } rows[192].Height = new GridLength(30); keyTabScroller.Content = keyGrid; List <Line> lines = new List <Line>(); List <Polygon> polygons = new List <Polygon>(); List <Label> labels = new List <Label>(); //////////////////////////LOOP UIELEMENTS DEFINITION//////////////////////////// for (int i = 0; i < 33; ++i) { Label lb0 = new Label { Content = "k" + i.ToString(), FontFamily = new FontFamily("Times New Roman"), FontSize = 16, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; Grid.SetColumn(lb0, 0); Grid.SetRow(lb0, i * 6 + 0); labels.Add(lb0); keyGrid.Children.Add(lb0); Label lb1 = new Label { Content = "k" + (i + 1).ToString(), FontFamily = new FontFamily("Times New Roman"), FontSize = 16, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; Grid.SetColumn(lb1, 7); Grid.SetRow(lb1, i * 6 + 0); labels.Add(lb1); keyGrid.Children.Add(lb1); TextBlock tb0 = new TextBlock { HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center, Foreground = new SolidColorBrush(Color.FromRgb(127, 127, 127)), FontStyle = FontStyles.Italic }; tb0.Inlines.Add(BitConverter.ToString(k.k[i].ToArray()).Replace("-", "")); Grid.SetColumn(tb0, 1); Grid.SetRow(tb0, i * 6 + 0); Grid.SetColumnSpan(tb0, 3); textBlocks.Add(tb0); keyGrid.Children.Add(tb0); TextBlock tb1 = new TextBlock { HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Center, Foreground = new SolidColorBrush(Color.FromRgb(127, 127, 127)), FontStyle = FontStyles.Italic }; tb1.Inlines.Add(BitConverter.ToString(k.k[i + 1].ToArray()).Replace("-", "")); Grid.SetColumn(tb1, 4); Grid.SetRow(tb1, i * 6 + 0); Grid.SetColumnSpan(tb1, 3); textBlocks.Add(tb1); keyGrid.Children.Add(tb1); if (i == 32) { break; } Line vertt = new Line { Stroke = Brushes.Black, X1 = 30, Y1 = 0, X2 = 30, Y2 = 60 }; Grid.SetColumn(vertt, 0); Grid.SetRow(vertt, i * 6 + 1); RenderOptions.SetEdgeMode(vertt, EdgeMode.Aliased); lines.Add(vertt); keyGrid.Children.Add(vertt); Polygon vertp = new Polygon { Fill = Brushes.Black, Points = new PointCollection(new List <Point> { new Point(30, 60), new Point(27, 50), new Point(33, 50) }), }; Grid.SetColumn(vertp, 0); Grid.SetRow(vertp, i * 6 + 1); polygons.Add(vertp); keyGrid.Children.Add(vertp); Line vertt1 = new Line { Stroke = Brushes.Black, X1 = 30, Y1 = 30, X2 = 30, Y2 = 60 }; Grid.SetColumn(vertt1, 6); Grid.SetRow(vertt1, i * 6 + 1); RenderOptions.SetEdgeMode(vertt1, EdgeMode.Aliased); lines.Add(vertt1); keyGrid.Children.Add(vertt1); Polygon vertp1 = new Polygon { Fill = Brushes.Black, Points = new PointCollection(new List <Point> { new Point(30, 60), new Point(27, 50), new Point(33, 50) }), }; Grid.SetColumn(vertp1, 6); Grid.SetRow(vertp1, i * 6 + 1); polygons.Add(vertp1); keyGrid.Children.Add(vertp1); Line vertt2 = new Line { Stroke = Brushes.Black, X1 = 40, Y1 = 0, X2 = 40, Y2 = 120 }; Grid.SetColumn(vertt2, 7); Grid.SetRow(vertt2, i * 6 + 1); Grid.SetRowSpan(vertt2, 3); RenderOptions.SetEdgeMode(vertt2, EdgeMode.Aliased); lines.Add(vertt2); keyGrid.Children.Add(vertt2); Label lb2 = new Label { Content = "C" + i.ToString(), FontFamily = new FontFamily("Times New Roman"), FontSize = 16, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(0, 5, 0, 0) }; Grid.SetColumn(lb2, 6); Grid.SetRow(lb2, i * 6 + 1); labels.Add(lb2); keyGrid.Children.Add(lb2); for (int j = 0; j < 3; ++j) { TextBlock tb = new TextBlock { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Bottom, Foreground = new SolidColorBrush(Color.FromRgb(127, 127, 127)), FontStyle = FontStyles.Italic }; tb.Inlines.Add(BitConverter.ToString(k.keyGenRounds[3 * i + j].ToArray()).Replace("-", "").Substring(0, 16) + "\n" + BitConverter.ToString(k.keyGenRounds[3 * i + j].ToArray()).Replace("-", "").Substring(16, 16)); Grid.SetColumn(tb, 5 - j * 2); Grid.SetRow(tb, i * 6 + 1); textBlocks.Add(tb); keyGrid.Children.Add(tb); Line t = new Line { Stroke = Brushes.Black, X1 = 0, Y1 = 15, X2 = 140, Y2 = 15 }; Grid.SetColumn(t, 1 + j * 2); Grid.SetRow(t, i * 6 + 2); RenderOptions.SetEdgeMode(t, EdgeMode.Aliased); lines.Add(t); keyGrid.Children.Add(t); Polygon p = new Polygon { Fill = Brushes.Black, Points = new PointCollection(new List <Point> { new Point(0, 15), new Point(10, 12), new Point(10, 18) }), }; Grid.SetColumn(p, 1 + j * 2); Grid.SetRow(p, i * 6 + 2); polygons.Add(p); keyGrid.Children.Add(p); } Button x0 = new Button { Content = "X", FontFamily = new FontFamily("Times New Roman"), FontSize = 18, Background = Brushes.Transparent }; Grid.SetColumn(x0, 0); Grid.SetRow(x0, i * 6 + 2); buttons.Add(x0); keyGrid.Children.Add(x0); x0.Click += new RoutedEventHandler(mainWindow.X_Click); Button l = new Button { Content = "L", FontFamily = new FontFamily("Times New Roman"), FontSize = 18, Background = Brushes.Transparent }; Grid.SetColumn(l, 2); Grid.SetRow(l, i * 6 + 2); buttons.Add(l); keyGrid.Children.Add(l); l.Click += new RoutedEventHandler(mainWindow.L_Click); Button s = new Button { Content = "S", FontFamily = new FontFamily("Times New Roman"), FontSize = 18, Background = Brushes.Transparent }; Grid.SetColumn(s, 4); Grid.SetRow(s, i * 6 + 2); buttons.Add(s); keyGrid.Children.Add(s); s.Click += new RoutedEventHandler(mainWindow.S_Click); Button x1 = new Button { Content = "X", FontFamily = new FontFamily("Times New Roman"), FontSize = 18, Background = Brushes.Transparent }; Grid.SetColumn(x1, 6); Grid.SetRow(x1, i * 6 + 2); buttons.Add(x1); keyGrid.Children.Add(x1); x1.Click += new RoutedEventHandler(mainWindow.X_Click); Line l2 = new Line { Stroke = Brushes.Black, X1 = 0, Y1 = 15, X2 = 40, Y2 = 15 }; Grid.SetColumn(l2, 7); Grid.SetRow(l2, i * 6 + 2); RenderOptions.SetEdgeMode(l2, EdgeMode.Aliased); lines.Add(l2); keyGrid.Children.Add(l2); Polygon p2 = new Polygon { Fill = Brushes.Black, Points = new PointCollection(new List <Point> { new Point(0, 15), new Point(10, 12), new Point(10, 18) }), }; Grid.SetColumn(p2, 7); Grid.SetRow(p2, i * 6 + 2); polygons.Add(p2); keyGrid.Children.Add(p2); Line l3 = new Line { Stroke = Brushes.Black, X1 = 30, Y1 = 0, X2 = 30, Y2 = 30 }; Grid.SetColumn(l3, 0); Grid.SetRow(l3, i * 6 + 3); RenderOptions.SetEdgeMode(l3, EdgeMode.Aliased); lines.Add(l3); keyGrid.Children.Add(l3); Line l4 = new Line { Stroke = Brushes.Black, X1 = 30, Y1 = 0, X2 = 700, Y2 = 60 }; Grid.SetColumn(l4, 0); Grid.SetColumnSpan(l4, 8); Grid.SetRow(l4, i * 6 + 4); RenderOptions.SetEdgeMode(l4, EdgeMode.Aliased); lines.Add(l4); keyGrid.Children.Add(l4); Line l5 = new Line { Stroke = Brushes.Black, X1 = 700, Y1 = 0, X2 = 30, Y2 = 60 }; Grid.SetColumn(l5, 0); Grid.SetColumnSpan(l5, 8); Grid.SetRow(l5, i * 6 + 4); RenderOptions.SetEdgeMode(l5, EdgeMode.Aliased); lines.Add(l5); keyGrid.Children.Add(l5); Line l6 = new Line { Stroke = Brushes.Black, X1 = 30, Y1 = 0, X2 = 30, Y2 = 30 }; Grid.SetColumn(l6, 0); Grid.SetRow(l6, i * 6 + 5); RenderOptions.SetEdgeMode(l6, EdgeMode.Aliased); lines.Add(l6); keyGrid.Children.Add(l6); Line l7 = new Line { Stroke = Brushes.Black, X1 = 40, Y1 = 0, X2 = 40, Y2 = 30 }; Grid.SetColumn(l7, 7); Grid.SetRow(l7, i * 6 + 5); RenderOptions.SetEdgeMode(l7, EdgeMode.Aliased); lines.Add(l7); keyGrid.Children.Add(l7); } }
public static void GenerateContent(MainWindow mainWindow, Kuznyechik k) { object wantedNode = mainWindow.FindName("introGrid"); Grid introGrid = wantedNode as Grid; List <RowDefinition> rows = new List <RowDefinition>(); for (int i = 0; i < 32; ++i) { rows.Add(new RowDefinition()); rows[i].Height = new GridLength(22); introGrid.RowDefinitions.Add(rows[i]); } List <ColumnDefinition> columns = new List <ColumnDefinition>(); for (int i = 0; i < 5; ++i) { columns.Add(new ColumnDefinition()); introGrid.ColumnDefinitions.Add(columns[i]); } columns[0].Width = new GridLength(50); columns[1].Width = new GridLength(250); columns[2].Width = new GridLength(40); columns[3].Width = new GridLength(80); columns[4].Width = new GridLength(250); for (int i = 0; i < 10; ++i) { Label introL1 = new Label() { Margin = new Thickness(0, -3, 0, -3), Content = "K[" + Convert.ToString(i) + "] = k[" + Convert.ToString((i / 2) * 8 - (i % 2) + 1) + "] = " }; Grid.SetRow(introL1, i); Grid.SetColumn(introL1, 3); introGrid.Children.Add(introL1); TextBox introTb1 = new TextBox() { IsReadOnly = true, Text = BitConverter.ToString(k.roundKeys[i].ToArray()).Replace("-", "").ToUpper(), BorderBrush = Brushes.Transparent, }; Grid.SetRow(introTb1, i); Grid.SetColumn(introTb1, 4); introGrid.Children.Add(introTb1); } for (int i = 0; i < 32; ++i) { Label introL0 = new Label() { Margin = new Thickness(0, -3, 0, -3), Content = "C[" + Convert.ToString(i) + "] = ", }; Grid.SetRow(introL0, i); Grid.SetColumn(introL0, 0); introGrid.Children.Add(introL0); TextBox introTb0 = new TextBox() { IsReadOnly = true, Text = BitConverter.ToString(k.C[i].ToArray()).Replace("-", "").ToUpper(), BorderBrush = Brushes.Transparent, }; Grid.SetRow(introTb0, i); Grid.SetColumn(introTb0, 1); introGrid.Children.Add(introTb0); } }