source: trunk/CrypPlugins/KeySearcher/Presentation/Controls/P2PQuickWatchPresentation.xaml.cs @ 2295

Last change on this file since 2295 was 2295, checked in by Sven Rech, 11 years ago

Prepared KeySearcher for Localization

File size: 2.7 KB
Line 
1using System;
2using System.Numerics;
3using System.Windows;
4using System.Windows.Controls;
5using KeySearcher;
6using KeySearcher.KeyPattern;
7using System.Globalization;
8
9namespace KeySearcherPresentation.Controls
10{
11    [Cryptool.PluginBase.Attributes.Localization("KeySearcher.Properties.Resources")]
12    public partial class P2PQuickWatchPresentation : UserControl
13    {
14        public static readonly DependencyProperty IsVerboseEnabledProperty = DependencyProperty.Register("IsVerboseEnabled", typeof(Boolean), typeof(P2PQuickWatchPresentation), new PropertyMetadata(false));
15        public Boolean IsVerboseEnabled
16        {
17            get { return (Boolean)GetValue(IsVerboseEnabledProperty); }
18            set { SetValue(IsVerboseEnabledProperty, value); }
19        }
20
21        public NumberFormatInfo nfi = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone();
22
23        public P2PQuickWatchPresentation()
24        {
25            InitializeComponent();
26        }
27
28        public static readonly DependencyProperty IsOpenCLEnabledProperty =
29            DependencyProperty.Register("IsOpenCLEnabled",
30                        typeof(Boolean),
31                        typeof(P2PQuickWatchPresentation), new PropertyMetadata(false));
32
33        public Boolean IsOpenCLEnabled
34        {
35            get { return (Boolean)GetValue(IsOpenCLEnabledProperty); }
36            set { SetValue(IsOpenCLEnabledProperty, value); }
37        }
38
39        public void UpdateSettings(KeySearcher.KeySearcher keySearcher, KeySearcherSettings keySearcherSettings)
40        {
41            IsVerboseEnabled = keySearcherSettings.VerbosePeerToPeerDisplay;
42
43            if (keySearcher.Pattern == null || !keySearcher.Pattern.testWildcardKey(keySearcherSettings.Key) || keySearcherSettings.ChunkSize == 0)
44            {
45                return;
46            }
47
48            var keyPattern = new KeyPattern(keySearcher.ControlMaster.getKeyPattern())
49                                 {WildcardKey = keySearcherSettings.Key};
50            var keysPerChunk = Math.Pow(2, keySearcherSettings.ChunkSize);
51            var keyPatternPool = new KeyPatternPool(keyPattern, new BigInteger(keysPerChunk));
52
53            if (keyPatternPool.Length > 9999999999)
54            {
55                TotalAmountOfChunks.Content = keyPatternPool.Length.ToString().Substring(0, 10) + "...";
56            }
57            else
58            {
59                TotalAmountOfChunks.Content = keyPatternPool.Length;
60            }
61
62            KeysPerChunk.Content = keysPerChunk;
63            TestedBits.Content = Math.Ceiling(Math.Log((double) keyPatternPool.Length*keysPerChunk, 2));
64        }
65    }
66}
Note: See TracBrowser for help on using the repository browser.